diff --git a/py/api.py b/py/api.py index e152cdc..404f41d 100644 --- a/py/api.py +++ b/py/api.py @@ -99,14 +99,13 @@ class API: @self.app.route('/interstellar_ai/api/voice_recognition', methods=['POST']) def voice_recognition(): - type = request.args.get('type') + recognition_type = request.args.get('type') audio = request.args.get('audio') option = request.args.get('option') - if type == "basic": - text = self.voice.basic_recognition(audio, option) - return jsonify({'status': 200, 'response': text}) - else: - return jsonify({'status': 401, 'response': "Invalid type"}) + if recognition_type == "basic": + return jsonify({'status': 200, 'response': self.voice.basic_recognition(audio, option)}) + + return jsonify({'status': 401, 'response': "Invalid type"}) @self.app.route('/interstellar_ai/api/weather', methods=['POST']) def get_weather(): diff --git a/py/voice.py b/py/voice.py index ddf2a6d..d589eab 100644 --- a/py/voice.py +++ b/py/voice.py @@ -4,20 +4,12 @@ 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: - text = r.recognize_google_cloud(source) - print("recognized as: " + text) - return text + return r.recognize_google_cloud(source) elif option == "offline": - print("offline") with audio as source: - text = r.recognize_sphinx(source) - print("recognized as: " + text) - return text + return r.recognize_sphinx(source) - print("nothing") return False