forked from React-Group/interstellar_ai
Compare commits
No commits in common. "a07961d65dd6add9d84b005619f6805be0cc7cfd" and "7ec0a192de0f2fd3c9d1c878ddd640293ff8417b" have entirely different histories.
a07961d65d
...
7ec0a192de
3 changed files with 30 additions and 10 deletions
11
py/api.py
11
py/api.py
|
@ -99,9 +99,16 @@ class API:
|
||||||
|
|
||||||
@self.app.route('/interstellar_ai/api/voice_recognition', methods=['POST'])
|
@self.app.route('/interstellar_ai/api/voice_recognition', methods=['POST'])
|
||||||
def voice_recognition():
|
def voice_recognition():
|
||||||
|
print(request.args)
|
||||||
|
recog_type = request.form.get('type')
|
||||||
|
print(recog_type)
|
||||||
audio = request.files.get('audio')
|
audio = request.files.get('audio')
|
||||||
text = self.voice.recognition(audio)
|
option = request.form.get('option')
|
||||||
return jsonify({'status': 200, 'response': text})
|
if recog_type == "basic":
|
||||||
|
text = self.voice.basic_recognition(audio, option)
|
||||||
|
return jsonify({'status': 200, 'response': text})
|
||||||
|
else:
|
||||||
|
return jsonify({'status': 401, 'response': "Invalid type"})
|
||||||
|
|
||||||
@self.app.route('/interstellar_ai/api/weather', methods=['POST'])
|
@self.app.route('/interstellar_ai/api/weather', methods=['POST'])
|
||||||
def get_weather():
|
def get_weather():
|
||||||
|
|
|
@ -13,5 +13,4 @@ python-weather
|
||||||
pycouchdb
|
pycouchdb
|
||||||
pyttsx3
|
pyttsx3
|
||||||
pip-licenses
|
pip-licenses
|
||||||
openai-whisper
|
openai-whisper
|
||||||
pydub
|
|
26
py/voice.py
26
py/voice.py
|
@ -1,10 +1,24 @@
|
||||||
import whisper
|
import speech_recognition as sr
|
||||||
|
|
||||||
|
|
||||||
class VoiceRecognition:
|
class VoiceRecognition:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def recognition(audio):
|
def basic_recognition(audio, option):
|
||||||
model = whisper.load_model("base")
|
print(type(audio))
|
||||||
result = model.transcribe(audio)
|
print("preparing")
|
||||||
print(result["text"])
|
r = sr.Recognizer()
|
||||||
return result["text"]
|
if option == "online":
|
||||||
|
with sr.AudioFile(audio) as source:
|
||||||
|
print("online")
|
||||||
|
text = r.recognize_google_cloud(source)
|
||||||
|
print("recognized as: " + text)
|
||||||
|
return text
|
||||||
|
elif option == "offline":
|
||||||
|
with sr.AudioFile(audio) as source:
|
||||||
|
print("offline")
|
||||||
|
text = r.recognize_sphinx(source)
|
||||||
|
print("recognized as: " + text)
|
||||||
|
return text
|
||||||
|
|
||||||
|
print("nothing")
|
||||||
|
return False
|
||||||
|
|
Loading…
Reference in a new issue