feat(voice): transcribe Telegram voice notes with SpeechRecognition
Add a voice message handler that downloads OGG audio, converts it to WAV via pydub/ffmpeg, and transcribes it with Google Speech Recognition (pt-BR) before feeding the text into the normal message pipeline. Also extract shared text processing into process_text_message, guard against updates without a text attribute, switch the default AI provider to openrouter with deepseek-v4-flash, and document the ffmpeg system requirement in DEPLOY.md.
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
import speech_recognition as sr
|
||||
|
||||
r = sr.Recognizer()
|
||||
m = sr.Microphone()
|
||||
|
||||
try:
|
||||
print("A moment of silence, please...")
|
||||
with m as source: r.adjust_for_ambient_noise(source)
|
||||
print("Set minimum energy threshold to {}".format(r.energy_threshold))
|
||||
while True:
|
||||
print("Say something!")
|
||||
with m as source: audio = r.listen(source)
|
||||
print("Got it! Now to recognize it...")
|
||||
try:
|
||||
# recognize speech using Google Speech Recognition
|
||||
value = r.recognize_google(audio)
|
||||
|
||||
print("You said {}".format(value))
|
||||
except sr.UnknownValueError:
|
||||
print("Oops! Didn't catch that")
|
||||
except sr.RequestError as e:
|
||||
print("Uh oh! Couldn't request results from Google Speech Recognition service; {0}".format(e))
|
||||
except KeyboardInterrupt:
|
||||
pass
|
||||
Reference in New Issue
Block a user