File tree Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Expand file tree Collapse file tree 2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change 11import asyncio
22import random
33
4+ import numpy as np
5+
46from agents import Agent , function_tool
57from agents .extensions .handoff_prompt import prompt_with_handoff_instructions
68from agents .voice import (
@@ -78,6 +80,9 @@ async def main():
7880 elif event .type == "voice_stream_event_lifecycle" :
7981 print (f"Received lifecycle event: { event .event } " )
8082
83+ # Add 1 second of silence to the end of the stream to avoid cutting off the last audio.
84+ player .add_audio (np .zeros (24000 * 1 , dtype = np .int16 ))
85+
8186
8287if __name__ == "__main__" :
8388 asyncio .run (main ())
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ def __enter__(self):
6262 return self
6363
6464 def __exit__ (self , exc_type , exc_value , traceback ):
65+ self .stream .stop () # wait for the stream to finish
6566 self .stream .close ()
6667
6768 def add_audio (self , audio_data : npt .NDArray [np .int16 ]):
You can’t perform that action at this time.
0 commit comments