Skip to content

Commit

Permalink
voiceRecoginz
Browse files Browse the repository at this point in the history
  • Loading branch information
hluo76 committed Nov 16, 2020
1 parent d8a7f09 commit 516bd83
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 212 deletions.
57 changes: 57 additions & 0 deletions src/VoiceRecog.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Nov 16 00:54:35 2020
@author: robin
"""

import speech_recognition as sr

r = sr.Recognizer()
mic = sr.Microphone()



def recognize_speech_from_mic(recognizer, microphone):

# check that recognizer and microphone arguments are appropriate type
if not isinstance(recognizer, sr.Recognizer):
raise TypeError("`recognizer` must be `Recognizer` instance")

if not isinstance(microphone, sr.Microphone):
raise TypeError("`microphone` must be `Microphone` instance")

# adjust the recognizer sensitivity to ambient noise and record audio
# from the microphone
with microphone as source:
recognizer.adjust_for_ambient_noise(source)
audio = recognizer.listen(source)

# set up the response object
response = {
"success": True,
"error": None,
"transcription": None
}

# try recognizing the speech in the recording
# if a RequestError or UnknownValueError exception is caught,
# update the response object accordingly
try:
response["transcription"] = recognizer.recognize_google(audio)
except sr.RequestError:
# API was unreachable or unresponsive
response["success"] = False
response["error"] = "API unavailable"
except sr.UnknownValueError:
# speech was unintelligible
response["error"] = "Unable to recognize speech"

return response


'''
response = recognize_speech_from_mic(r, mic)
print(response)
'''
18 changes: 18 additions & 0 deletions src/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 14 18:54:20 2020
@author: robin
"""

import json

file = '/Users/robin/Downloads/video/src/output/lists/actions_present/'

with open(file + 'train_labeled.json') as json_file:
data = json.load(json_file)


for key, val in data:

Empty file removed src/vqatools/__init__.py
Empty file.
97 changes: 0 additions & 97 deletions src/vqatools/visual7w.py

This file was deleted.

115 changes: 0 additions & 115 deletions src/vqatools/vqa.py

This file was deleted.

0 comments on commit 516bd83

Please sign in to comment.