fix(examples): make sure audio playback finishes
This commit is contained in:
parent
ad020b73b5
commit
2104f5400b
2 changed files with 6 additions and 0 deletions
|
|
@ -1,6 +1,8 @@
|
|||
import asyncio
|
||||
import random
|
||||
|
||||
import numpy as np
|
||||
|
||||
from agents import Agent, function_tool
|
||||
from agents.extensions.handoff_prompt import prompt_with_handoff_instructions
|
||||
from agents.voice import (
|
||||
|
|
@ -78,6 +80,9 @@ async def main():
|
|||
elif event.type == "voice_stream_event_lifecycle":
|
||||
print(f"Received lifecycle event: {event.event}")
|
||||
|
||||
# Add 1 second of silence to the end of the stream to avoid cutting off the last audio.
|
||||
player.add_audio(np.zeros(24000 * 1, dtype=np.int16))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
|
|
|
|||
|
|
@ -62,6 +62,7 @@ class AudioPlayer:
|
|||
return self
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
self.stream.stop() # wait for the stream to finish
|
||||
self.stream.close()
|
||||
|
||||
def add_audio(self, audio_data: npt.NDArray[np.int16]):
|
||||
|
|
|
|||
Loading…
Reference in a new issue