examples(twilio-chatbot): create sample rate variable
This commit is contained in:
@@ -36,6 +36,8 @@ load_dotenv(override=True)
|
||||
logger.remove(0)
|
||||
logger.add(sys.stderr, level="DEBUG")
|
||||
|
||||
SAMPLE_RATE = 8000
|
||||
|
||||
|
||||
async def save_audio(server_name: str, audio: bytes, sample_rate: int, num_channels: int):
|
||||
if len(audio) > 0:
|
||||
@@ -61,13 +63,13 @@ async def run_bot(websocket_client: WebSocket, stream_sid: str, testing: bool):
|
||||
params=FastAPIWebsocketParams(
|
||||
audio_in_enabled=True,
|
||||
audio_out_enabled=True,
|
||||
audio_out_sample_rate=8000,
|
||||
audio_out_sample_rate=SAMPLE_RATE,
|
||||
add_wav_header=False,
|
||||
vad_enabled=True,
|
||||
vad_analyzer=SileroVADAnalyzer(sample_rate=8000),
|
||||
vad_analyzer=SileroVADAnalyzer(sample_rate=SAMPLE_RATE),
|
||||
vad_audio_passthrough=True,
|
||||
serializer=TwilioFrameSerializer(
|
||||
stream_sid, TwilioFrameSerializer.InputParams(sample_rate=8000)
|
||||
stream_sid, TwilioFrameSerializer.InputParams(sample_rate=SAMPLE_RATE)
|
||||
),
|
||||
),
|
||||
)
|
||||
@@ -76,14 +78,14 @@ async def run_bot(websocket_client: WebSocket, stream_sid: str, testing: bool):
|
||||
|
||||
stt = DeepgramSTTService(
|
||||
api_key=os.getenv("DEEPGRAM_API_KEY"),
|
||||
live_options=LiveOptions(sample_rate=8000),
|
||||
live_options=LiveOptions(sample_rate=SAMPLE_RATE),
|
||||
audio_passthrough=True,
|
||||
)
|
||||
|
||||
tts = CartesiaTTSService(
|
||||
api_key=os.getenv("CARTESIA_API_KEY"),
|
||||
voice_id="79a125e8-cd45-4c13-8a67-188112f4dd22", # British Lady
|
||||
sample_rate=8000,
|
||||
sample_rate=SAMPLE_RATE,
|
||||
push_silence_after_stop=testing,
|
||||
)
|
||||
|
||||
@@ -99,7 +101,7 @@ async def run_bot(websocket_client: WebSocket, stream_sid: str, testing: bool):
|
||||
|
||||
# NOTE: Watch out! This will save all the conversation in memory. You can
|
||||
# pass `buffer_size` to get periodic callbacks.
|
||||
audiobuffer = AudioBufferProcessor(sample_rate=8000)
|
||||
audiobuffer = AudioBufferProcessor(sample_rate=SAMPLE_RATE)
|
||||
|
||||
pipeline = Pipeline(
|
||||
[
|
||||
|
||||
Reference in New Issue
Block a user