forked from Soumya44/Speech_Rcognition_Using_Python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeechtest.py
More file actions
35 lines (28 loc) · 902 Bytes
/
speechtest.py
File metadata and controls
35 lines (28 loc) · 902 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
import speech_recognition as sr
from gtts import gTTS
import os
# get audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
print("Speak:")
audio = r.listen(source)
mytext=r.recognize_google(audio)
try:
print("You said " + r.recognize_google(audio))
except sr.UnknownValueError:
print("Could not understand audio")
except sr.RequestError as e:
print("Could not request results; {0}".format(e))
# The text that you want to convert to audio
# Language in which you want to convert
language = 'en'
# Passing the text and language to the engine,
# here we have marked slow=False. Which tells
# the module that the converted audio should
# have a high speed
myobj = gTTS(text=mytext, lang=language, slow=False)
# Saving the converted audio in a mp3 file named
# welcome
myobj.save("welcome.mp3")
# Playing the converted file
os.system("start welcome.mp3")