forked from React-Group/interstellar_ai
		
	Compare commits
	
		
			5 commits
		
	
	
		
			7ec0a192de
			...
			a07961d65d
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| a07961d65d | |||
| 
							 | 
						ab12b796ec | ||
| 
							 | 
						8cc9b1b015 | ||
| 
							 | 
						58d1a68bac | ||
| 9d27354c1e | 
					 3 changed files with 10 additions and 30 deletions
				
			
		
							
								
								
									
										11
									
								
								py/api.py
									
										
									
									
									
								
							
							
						
						
									
										11
									
								
								py/api.py
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -99,16 +99,9 @@ class API:
 | 
			
		|||
 | 
			
		||||
        @self.app.route('/interstellar_ai/api/voice_recognition', methods=['POST'])
 | 
			
		||||
        def voice_recognition():
 | 
			
		||||
            print(request.args)
 | 
			
		||||
            recog_type = request.form.get('type')
 | 
			
		||||
            print(recog_type)
 | 
			
		||||
            audio = request.files.get('audio')
 | 
			
		||||
            option = request.form.get('option')
 | 
			
		||||
            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"})
 | 
			
		||||
            text = self.voice.recognition(audio)
 | 
			
		||||
            return jsonify({'status': 200, 'response': text})
 | 
			
		||||
 | 
			
		||||
        @self.app.route('/interstellar_ai/api/weather', methods=['POST'])
 | 
			
		||||
        def get_weather():
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -14,3 +14,4 @@ pycouchdb
 | 
			
		|||
pyttsx3
 | 
			
		||||
pip-licenses
 | 
			
		||||
openai-whisper
 | 
			
		||||
pydub
 | 
			
		||||
							
								
								
									
										26
									
								
								py/voice.py
									
										
									
									
									
								
							
							
						
						
									
										26
									
								
								py/voice.py
									
										
									
									
									
								
							| 
						 | 
				
			
			@ -1,24 +1,10 @@
 | 
			
		|||
import speech_recognition as sr
 | 
			
		||||
import whisper
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class VoiceRecognition:
 | 
			
		||||
    @staticmethod
 | 
			
		||||
    def basic_recognition(audio, option):
 | 
			
		||||
        print(type(audio))
 | 
			
		||||
        print("preparing")
 | 
			
		||||
        r = sr.Recognizer()
 | 
			
		||||
        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
 | 
			
		||||
    def recognition(audio):
 | 
			
		||||
        model = whisper.load_model("base")
 | 
			
		||||
        result = model.transcribe(audio)
 | 
			
		||||
        print(result["text"])
 | 
			
		||||
        return result["text"]
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue