interstellar_ai/py/voice.py

24 lines
668 B
Python
Raw Normal View History

2024-09-24 09:55:23 +02:00
import speech_recognition as sr
class VoiceRecognition:
@staticmethod
def basic_recognition(audio, option):
2024-09-26 09:32:14 +02:00
print("preparing")
2024-09-24 09:55:23 +02:00
r = sr.Recognizer()
if option == "online":
2024-09-26 09:32:14 +02:00
print("online")
2024-09-26 08:33:11 +02:00
with audio as source:
2024-09-26 09:32:14 +02:00
text = r.recognize_google_cloud(source)
print("recognized as: " + text)
return text
elif option == "offline":
2024-09-26 09:32:14 +02:00
print("offline")
2024-09-26 08:33:11 +02:00
with audio as source:
2024-09-26 09:32:14 +02:00
text = r.recognize_sphinx(source)
print("recognized as: " + text)
return text
2024-09-26 09:32:14 +02:00
print("nothing")
return False