interstellar_ai/py/voice.py
2024-09-26 09:52:31 +02:00

24 lines
731 B
Python

import speech_recognition as sr
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