File tree 2 files changed +6
-0
lines changed
2 files changed +6
-0
lines changed Original file line number Diff line number Diff line change 1
1
import asyncio
2
2
import random
3
3
4
+ import numpy as np
5
+
4
6
from agents import Agent , function_tool
5
7
from agents .extensions .handoff_prompt import prompt_with_handoff_instructions
6
8
from agents .voice import (
@@ -78,6 +80,9 @@ async def main():
78
80
elif event .type == "voice_stream_event_lifecycle" :
79
81
print (f"Received lifecycle event: { event .event } " )
80
82
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
+
81
86
82
87
if __name__ == "__main__" :
83
88
asyncio .run (main ())
Original file line number Diff line number Diff line change @@ -62,6 +62,7 @@ def __enter__(self):
62
62
return self
63
63
64
64
def __exit__ (self , exc_type , exc_value , traceback ):
65
+ self .stream .stop () # wait for the stream to finish
65
66
self .stream .close ()
66
67
67
68
def add_audio (self , audio_data : npt .NDArray [np .int16 ]):
You can’t perform that action at this time.
0 commit comments