interstellar_ai/py/voice.py

25 lines
731 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:52:31 +02:00
print(type(audio))
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:52:31 +02:00
with sr.AudioFile(audio) as source:
print("online")
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:52:31 +02:00
with sr.AudioFile(audio) as source:
print("offline")
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