forked from React-Group/interstellar_ai
main #24
2 changed files with 12 additions and 3 deletions
|
@ -103,7 +103,8 @@ class API:
|
|||
audio = request.args.get('audio')
|
||||
option = request.args.get('option')
|
||||
if recognition_type == "basic":
|
||||
return jsonify({'status': 200, 'response': self.voice.basic_recognition(audio, option)})
|
||||
text = self.voice.basic_recognition(audio, option)
|
||||
return jsonify({'status': 200, 'response': text})
|
||||
|
||||
return jsonify({'status': 401, 'response': "Invalid type"})
|
||||
|
||||
|
|
12
py/voice.py
12
py/voice.py
|
@ -4,12 +4,20 @@ import speech_recognition as sr
|
|||
class VoiceRecognition:
|
||||
@staticmethod
|
||||
def basic_recognition(audio, option):
|
||||
print("preparing")
|
||||
r = sr.Recognizer()
|
||||
if option == "online":
|
||||
print("online")
|
||||
with audio as source:
|
||||
return r.recognize_google_cloud(source)
|
||||
text = r.recognize_google_cloud(source)
|
||||
print("recognized as: " + text)
|
||||
return text
|
||||
elif option == "offline":
|
||||
print("offline")
|
||||
with audio as source:
|
||||
return r.recognize_sphinx(source)
|
||||
text = r.recognize_sphinx(source)
|
||||
print("recognized as: " + text)
|
||||
return text
|
||||
|
||||
print("nothing")
|
||||
return False
|
||||
|
|
Loading…
Reference in a new issue