Compare commits

...

5 commits

3 changed files with 10 additions and 30 deletions

View file

@ -99,16 +99,9 @@ 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')
option = request.form.get('option') text = self.voice.recognition(audio)
if recog_type == "basic": return jsonify({'status': 200, 'response': text})
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():

View file

@ -13,4 +13,5 @@ python-weather
pycouchdb pycouchdb
pyttsx3 pyttsx3
pip-licenses pip-licenses
openai-whisper openai-whisper
pydub

View file

@ -1,24 +1,10 @@
import speech_recognition as sr import whisper
class VoiceRecognition: class VoiceRecognition:
@staticmethod @staticmethod
def basic_recognition(audio, option): def recognition(audio):
print(type(audio)) model = whisper.load_model("base")
print("preparing") result = model.transcribe(audio)
r = sr.Recognizer() print(result["text"])
if option == "online": return result["text"]
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