python pyttsx3文本转语音_如何使用python pyttsx3和sapi5将文本文件转换为mp3文件?
我试过布莱恩的解决办法,但没用。在我搜索了一下,我不知道如何用pyttx3将语音保存到mp3中,但我找到了另一个没有pyttx3的解决方案。在它可以取.txt文件直接输出.wav文件def txt_zu_wav(eingabe, ausgabe, text_aus_datei = True, geschwindigkeit = 2, Stimmenname = "Zira"):from comty
我试过布莱恩的解决办法,但没用。在
我搜索了一下,我不知道如何用pyttx3将语音保存到mp3中,但我找到了另一个没有pyttx3的解决方案。在
它可以取.txt文件直接输出.wav文件def txt_zu_wav(eingabe, ausgabe, text_aus_datei = True, geschwindigkeit = 2, Stimmenname = "Zira"):
from comtypes.client import CreateObject
engine = CreateObject("SAPI.SpVoice")
engine.rate = geschwindigkeit # von -10 bis 10
for stimme in engine.GetVoices():
if stimme.GetDescription().find(Stimmenname) >= 0:
engine.Voice = stimme
break
else:
print("Fehler Stimme nicht gefunden -> Standard wird benutzt")
if text_aus_datei:
datei = open(eingabe, 'r')
text = datei.read()
datei.close()
else:
text = eingabe
stream = CreateObject("SAPI.SpFileStream")
from comtypes.gen import SpeechLib
stream.Open(ausgabe, SpeechLib.SSFMCreateForWrite)
engine.AudioOutputStream = stream
engine.speak(text)
stream.Close()
txt_zu_wav("test.txt", "test_1.wav")
txt_zu_wav("It also works with a string instead of a file path", "test_2.wav", False)
这是在Windows10上用Python3.7.4测试的。在
更多推荐
所有评论(0)