pyttsx3 save to file

Solutions on MaxInterview for pyttsx3 save to file by the best coders in the world

showing results for - "pyttsx3 save to file"
Elena
14 Jan 2020
1def txt_zu_wav(eingabe, ausgabe, text_aus_datei = True, geschwindigkeit = 2, Stimmenname = "Zira"):
2    from comtypes.client import CreateObject
3    engine = CreateObject("SAPI.SpVoice")
4
5    engine.rate = geschwindigkeit # von -10 bis 10
6
7    for stimme in engine.GetVoices():
8        if stimme.GetDescription().find(Stimmenname) >= 0:
9            engine.Voice = stimme
10            break
11    else:
12        print("Fehler Stimme nicht gefunden -> Standard wird benutzt")
13
14    if text_aus_datei:
15        datei = open(eingabe, 'r')
16        text = datei.read()
17        datei.close()
18    else:
19        text = eingabe
20
21    stream = CreateObject("SAPI.SpFileStream")
22    from comtypes.gen import SpeechLib
23
24    stream.Open(ausgabe, SpeechLib.SSFMCreateForWrite)
25    engine.AudioOutputStream = stream
26    engine.speak(text)
27
28    stream.Close()
29
30txt_zu_wav("test.txt", "test_1.wav")
31txt_zu_wav("It also works with a string instead of a file path", "test_2.wav", False)
32
Elly
02 Jun 2016
1import pyttsx3
2engine = pyttsx3.init("sapi5")
3voices = engine.getProperty("voices")[0] 
4engine.setProperty('voice', voices)
5text = 'Your Text'
6engine.save_to_file(text, 'name.mp3')
7engine.runAndWait() # don't forget to use this line
Luka
17 Oct 2020
1import pyttsx3
2from gtts import gTTS
3
4engine = pyttsx3.init(driverName='sapi5')
5infile = "tanjil.txt"
6f = open(infile, 'r')
7theText = f.read()
8f.close()
9
10#Saving part starts from here 
11tts = gTTS(text=theText, lang='en')
12tts.save("saved_file.mp3")
13print("File saved!")
14