first pass at turn based conversation
This commit is contained in:
parent
d1118d375e
commit
518a0f2b53
40 changed files with 503 additions and 99 deletions
6
vocode/turn_based/transcriber/base_transcriber.py
Normal file
6
vocode/turn_based/transcriber/base_transcriber.py
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
from pydub import AudioSegment
|
||||
|
||||
|
||||
class BaseTranscriber:
|
||||
def transcribe(self, audio_segment: AudioSegment) -> str:
|
||||
raise NotImplementedError
|
||||
21
vocode/turn_based/transcriber/whisper_transcriber.py
Normal file
21
vocode/turn_based/transcriber/whisper_transcriber.py
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
from pydub import AudioSegment
|
||||
import io
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
import openai
|
||||
|
||||
from vocode.turn_based.transcriber.base_transcriber import BaseTranscriber
|
||||
|
||||
load_dotenv()
|
||||
|
||||
openai.api_key = os.getenv("OPENAI_API_KEY")
|
||||
|
||||
|
||||
class WhisperTranscriber(BaseTranscriber):
|
||||
def transcribe(self, audio_segment: AudioSegment) -> str:
|
||||
in_memory_wav = io.BytesIO()
|
||||
audio_segment.export(in_memory_wav, format="wav")
|
||||
in_memory_wav.seek(0)
|
||||
in_memory_wav.name = "whisper.wav"
|
||||
transcript = openai.Audio.transcribe("whisper-1", in_memory_wav)
|
||||
return transcript.text
|
||||
Loading…
Add table
Add a link
Reference in a new issue