我有以下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)