Merge pull request 'simple_chat, voice_recognition' (#22) from YasinOnm08/ai-virtual-assistant:main into main
Reviewed-on: https://interstellardevelopment.org/code/code/React-Group/ai-virtual-assistant/pulls/22
This commit is contained in:
		
						commit
						e1529430cc
					
				
					 2 changed files with 33 additions and 1 deletions
				
			
		|  | @ -1,6 +1,5 @@ | ||||||
| from api import API | from api import API | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| class CLIChat: | class CLIChat: | ||||||
|     @staticmethod |     @staticmethod | ||||||
|     def chat(): |     def chat(): | ||||||
|  |  | ||||||
							
								
								
									
										33
									
								
								py/voice_recognition.py
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										33
									
								
								py/voice_recognition.py
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,33 @@ | ||||||
|  | import speech_recognition as sr | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Voice: | ||||||
|  |     @staticmethod | ||||||
|  |     def listen(): | ||||||
|  |         recognizer = sr.Recognizer() | ||||||
|  | 
 | ||||||
|  |         try: | ||||||
|  |             recognizer = sr.Recognizer() | ||||||
|  |             with sr.Microphone() as source: | ||||||
|  |                 print("Adjusting for ambient noise...") | ||||||
|  |                 recognizer.adjust_for_ambient_noise(source) | ||||||
|  |                 print("Listening...") | ||||||
|  |                 audio_data = recognizer.listen(source) | ||||||
|  |                 print("Audio captured") | ||||||
|  |                 try: | ||||||
|  |                     text = recognizer.recognize_sphinx(audio_data)  # Using Google Web Speech API | ||||||
|  |                 except sr.UnknownValueError: | ||||||
|  |                     text = "ERROR" | ||||||
|  |                 except sr.RequestError as e: | ||||||
|  |                     text = "ERROR" | ||||||
|  |                  | ||||||
|  |         except sr.RequestError as e: | ||||||
|  |             text = "ERROR" | ||||||
|  |         except sr.UnknownValueError: | ||||||
|  |             text = "ERROR" | ||||||
|  |         except Exception as e: | ||||||
|  |             text = "ERROR" | ||||||
|  |         return text | ||||||
|  |     print(listen()) | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue