|
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.") |
|
|