#!/usr/bin/env python
from AppKit import NSSpeechSynthesizer
import sys
import Foundation
if len(sys.argv) < 2:
text = raw_input('type text to speak> ')
else:
text = sys.argv[1]
nssp = NSSpeechSynthesizer
ve = nssp.alloc().init()
ve.setRate_(100)
url = Foundation.NSURL.fileURLWithPath_('yourpath/test.aiff')
ve.startSpeakingString_toURL_(text,url)
可以使用更高级的SAPI包装器将输出保存到wav文件。例如,你可以尝试
https://github.com/DeepHorizons/tts
代码应该如下所示:
下面是一个允许您访问NSSpeechSynthesizer API的示例
可以使用subprocess使用-w参数调用espeak。
这将在不大声读出的情况下写入file_name.wav。如果您的文本在一个文件中(例如text.txt),则需要使用-f参数(“-f”+text)调用espeak。我建议您阅读espeak man pages以查看所有选项。
希望这有帮助。
相关问题 更多 >
编程相关推荐