| 25 | return '' |
| 26 | |
| 27 | class APIWhisperTranscriber: |
| 28 | def __init__(self, api_key=None): |
| 29 | self.client = OpenAI(api_key=api_key) |
| 30 | |
| 31 | def get_transcription(self, wav_file_path): |
| 32 | try: |
| 33 | with open(wav_file_path, "rb") as audio_file: |
| 34 | result = self.client.audio.transcriptions.create( |
| 35 | model="whisper-1", |
| 36 | file=audio_file |
| 37 | ) |
| 38 | return result.text.strip() |
| 39 | except Exception as e: |
| 40 | print(e) |
| 41 | return '' |