-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
hluo76
committed
Nov 16, 2020
1 parent
d8a7f09
commit 516bd83
Showing
5 changed files
with
75 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
''' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.