-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeech_rec.py
More file actions
42 lines (33 loc) · 964 Bytes
/
speech_rec.py
File metadata and controls
42 lines (33 loc) · 964 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import os
import speech_recognition as sr
from gtts import gTTS
import pyaudio
import pyttsx3
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()
voice = ""
myPyAudio = pyaudio.PyAudio()
print("Seeing pyaudio devices:", myPyAudio.get_device_count())
print(sr.Microphone.list_microphone_names())
mic = sr.Microphone()
print("Starting...")
while True:
r = sr.Recognizer()
with mic as source:
try:
r.adjust_for_ambient_noise(source)
audio = r.listen(source)
text = r.recognize_google(audio)
print(text)
if text == "stop":
break
text = r.recognize_google(audio)
voice += str(text)
engine = pyttsx3.init()
engine.say("I will speak this text")
engine.runAndWait()
except:
print("say something...")
hr = gTTS(text=voice, lang="en", slow=False)
hr.save("1.wav")