1The best library because you dont have to save the
2text file or open the file to start the speech
3
4pip install pyttsx3
5
6import pyttsx3
7engine = pyttsx3.init()
8engine.say("Hello world")
9engine.runAndWait()
1 import speech_recognition as sr
2
3
4 def main():
5
6 r = sr.Recognizer()
7
8 with sr.Microphone() as source:
9 r.adjust_for_ambient_noise(source)
10
11 audio = r.listen(source)
12
13 try:
14
15 print(r.recognize_google(audio))
16
17 except Exception as e:
18 print("Error : " + str(e))
19
20
21 with open("recorded.wav", "wb") as f:
22 f.write(audio.get_wav_data())
23
24
25 if __name__ == "__main__":
26 main()
1# please subscribe my channel - https://bit.ly/2Me2CfB
2from gtts import gTTS
3
4speech = gTTS(text="hello")
5speech.save('speech.wav')