Skip to content

Commit

Permalink
Merge pull request sourabhjagtap95#41 from ozamed/master
Browse files Browse the repository at this point in the history
Speech To Text & Text To Speech
  • Loading branch information
sourabhjagtap95 authored Oct 18, 2020
2 parents 16d2725 + 67bac57 commit 3ceb602
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions VoiceIO/main/speechInput.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello guys, this is an example.
Empty file added VoiceIO/main/speechOutput.txt
Empty file.
22 changes: 22 additions & 0 deletions VoiceIO/main/voiceInput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import speech_recognition as sr

def SpeechRecognition():
r = sr.Recognizer()
with sr.Microphone() as source:
print('Say something...')
r.pause_threshold = 1
r.adjust_for_ambient_noise(source, duration=1)
audio = r.listen(source)
try:
outputFile = open("speechOutput.txt","a")
userSpeech = r.recognize_google(audio).lower()
print('You said: ' + userSpeech + '\n')
outputFile.write(userSpeech + '\n')
outputFile.close()

except sr.UnknownValueError:
print('....')

while True:
SpeechRecognition()

8 changes: 8 additions & 0 deletions VoiceIO/main/voiceOutput.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import pyttsx3

engine = pyttsx3.init()

inputFile = open("speechInput.txt","r")

engine.say(inputFile.read())
engine.runAndWait()
2 changes: 2 additions & 0 deletions VoiceIO/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pyttsx3==2.87
SpeechRecognition==3.8.1

0 comments on commit 3ceb602

Please # to comment.