File size: 720 Bytes
2d31940 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
import wave
import io
from groq import Groq
class SpeechToText:
def __init__(self):
self.client = Groq()
def record_and_transcribe(self, audio_bytes):
wav_buffer = io.BytesIO(audio_bytes)
try:
transcription = self.client.audio.transcriptions.create(
file=("audio.wav", wav_buffer),
model="whisper-large-v3-turbo"
)
return transcription.text
except Exception as e:
print(f"Error transcribing: {e}")
return str(e)
finally:
wav_buffer.close()
if __name__ == "__main__":
print("This script is designed to be used as a module, not run directly.")
|