small fix?

This commit is contained in:
Patrick_Pluto 2024-09-26 10:43:39 +02:00
parent f12014833c
commit 58d1a68bac
2 changed files with 24 additions and 3 deletions

View file

@ -14,3 +14,4 @@ pycouchdb
pyttsx3 pyttsx3
pip-licenses pip-licenses
openai-whisper openai-whisper
pydub

View file

@ -1,20 +1,40 @@
import speech_recognition as sr import speech_recognition as sr
from pydub import AudioSegment
class VoiceRecognition: class VoiceRecognition:
@staticmethod def check_audio_format(self, file_path):
def basic_recognition(audio, option): try:
audio = AudioSegment.from_ogg(file_path)
print(f"Audio format: {audio.format}")
return True
except Exception as e:
print(f"Error reading audio file: {e}")
return False
def basic_recognition(self, audio, option):
print(type(audio)) print(type(audio))
print("preparing") print("preparing")
r = sr.Recognizer() r = sr.Recognizer()
# Read the data from the FileStorage object
audio_data = audio.read()
# Write the audio data to a file
with open('output.wav', 'wb') as file:
file.write(audio_data)
self.check_audio_format(audio)
if option == "online": if option == "online":
with sr.AudioFile(audio) as source: with sr.AudioFile(audio) as source:
print(type(source))
print("online") print("online")
text = r.recognize_google_cloud(source) text = r.recognize_google_cloud(source)
print("recognized as: " + text) print("recognized as: " + text)
return text return text
elif option == "offline": elif option == "offline":
with sr.AudioFile(audio) as source: with sr.AudioFile(audio) as source:
print(type(source))
print("offline") print("offline")
text = r.recognize_sphinx(source) text = r.recognize_sphinx(source)
print("recognized as: " + text) print("recognized as: " + text)