将Mac合成语音输出写入文件

时间:2016-10-25 00:19:34

标签: python macos text-to-speech

我有以下Python代码,它输出语音文字"这是一个测试"。有人能告诉我如何将此输出重定向到音频文件吗?

from  AppKit import NSSpeechSynthesizer
import time

nssp = NSSpeechSynthesizer
ve = nssp.alloc().init()
from_voice = "com.apple.speech.synthesis.voice.Alex"

data = u'''
This is a test.
'''

def say_data (data):
        ve.setVoice_(from_voice)
        ve.startSpeakingString_(data)
        time.sleep(1)
        while ve.isSpeaking():
             time.sleep(1)

say_data (data)

0 个答案:

没有答案