nextchat / ai /_audiotranscribe.py
shoaibatservionsoft
translation
c05b3cb
raw
history blame contribute delete
478 Bytes
import speech_recognition as sr
import os
r = sr.Recognizer()
def audio_transcribe(filename):
global r
try:
path = f"./tmp/{filename}"
audio = sr.AudioFile(f"./tmp/{filename}")
with audio as source:
audio = r.record(source)
text = r.recognize_whisper(audio)
# delete file
os.remove(path)
return text
except Exception as e:
print(e)
return False