Hello World

This commit is contained in:
Patrick_Pluto 2024-09-30 11:47:58 +02:00
parent 8dbb1c9169
commit 1e05319266

View file

@ -8,24 +8,18 @@ class VoiceRecognition:
def recognition(audio): def recognition(audio):
audio_buffer = io.BytesIO(audio.read()) audio_buffer = io.BytesIO(audio.read())
try: audio_segment = AudioSegment.from_file(audio_buffer, format="ogg")
audio_segment = AudioSegment.from_file(audio_buffer, format="ogg")
wav_io = io.BytesIO() wav_io = io.BytesIO()
audio_segment.export(wav_io, format="wav") audio_segment.export(wav_io, format="wav")
wav_io.seek(0) wav_io.seek(0)
except:
print("audio to wav failed")
model_size = "base" model_size = "base"
model = WhisperModel(model_size, device="cpu", compute_type=" ") model = WhisperModel(model_size, device="cpu", compute_type="int8")
segments, _ = model.transcribe(wav_io) segments, _ = model.transcribe(wav_io)
transcription = "" transcription = ""
for segment in segments: for segment in segments:
transcription += segment.text + " " transcription += segment.text + " "
result = transcription.strip() result = transcription.strip()
print(result)
return result return result
# npm install @ffmpeg/ffmpeg @ffmpeg/util @ffmpeg/types @ffmpeg/core-mt