将Mac合成语音输出写入fi

2024-05-17 00:08:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我有下面的Python代码,它输出口语文本“thisatest”。有人能告诉我如何将输出重定向到音频文件吗?你知道吗

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)

Tags: 代码from文本importdatatimevesleep