diff --git a/py/voice.py b/py/voice.py index 24d12ac..8aeb3e0 100644 --- a/py/voice.py +++ b/py/voice.py @@ -7,25 +7,19 @@ class VoiceRecognition: @staticmethod def recognition(audio): audio_buffer = io.BytesIO(audio.read()) - - try: - audio_segment = AudioSegment.from_file(audio_buffer, format="ogg") - - wav_io = io.BytesIO() - audio_segment.export(wav_io, format="wav") - wav_io.seek(0) - except: - print("audio to wav failed") - + + audio_segment = AudioSegment.from_file(audio_buffer, format="ogg") + + wav_io = io.BytesIO() + audio_segment.export(wav_io, format="wav") + wav_io.seek(0) + 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) transcription = "" for segment in segments: transcription += segment.text + " " result = transcription.strip() - print(result) return result - -# npm install @ffmpeg/ffmpeg @ffmpeg/util @ffmpeg/types @ffmpeg/core-mt \ No newline at end of file