interstellar_ai/py/voice.py
2024-09-26 09:32:14 +02:00

23 lines
668 B
Python

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
elif option == "offline":
print("offline")
with audio as source:
text = r.recognize_sphinx(source)
print("recognized as: " + text)
return text
print("nothing")
return False