Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

how to record pyttsx3 file using python

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)
Comment

how to record pyttsx3 file using python

import pyttsx3
from gtts import gTTS

engine = pyttsx3.init(driverName='sapi5')
infile = "tanjil.txt"
f = open(infile, 'r')
theText = f.read()
f.close()

#Saving part starts from here 
tts = gTTS(text=theText, lang='en')
tts.save("saved_file.mp3")
print("File saved!")
Comment

PREVIOUS NEXT
Code Example
Python :: MySQLdb/_mysql.c:46:10: fatal error: Python.h: No such file or directory 
Python :: write json to file python 
Python :: print a random word from list python 
Python :: python create a matrix with one in diagonal 
Python :: how to find the version of python command linw 
Python :: pandas convert date column to year and month 
Python :: plot bounds python 
Python :: python order 2d array by secode element 
Python :: logging the terminal output to a file 
Python :: Python find inverse of matrix 
Python :: python strip newline from string 
Python :: python selenium partial class name 
Python :: how to check if everything inside a list is unique 
Python :: force utf-8 encoding python 
Python :: Entry border color in tkinter 
Python :: python get lines from text file 
Python :: python exe not working on other pc 
Python :: python pandas convert comma separated number string to integer list 
Python :: how to make python remove the duplicates in list 
Python :: sqlalchemy lock row 
Python :: Get all columns with particular name in string 
Python :: selenium zoom out python 
Python :: how to define dtype of each column before actually reading csv file 
Python :: python csv read header only 
Python :: python get lan ip 
Python :: autopy in python install 
Python :: drop column dataframe 
Python :: merge multiple csv files 
Python :: letter frequency counter python 
Python :: set dtype for multiple columns pandas 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =