@@ -825,14 +825,7 @@ async def send_audio_async(
825825 """
826826 connection = self ._get_connection (conversation_id = conversation_id )
827827
828- with wave .open (filename , "rb" ) as wav_file :
829- # Read WAV parameters
830- num_channels = wav_file .getnchannels ()
831- sample_width = wav_file .getsampwidth () # Should be 2 bytes for PCM16
832- frame_rate = wav_file .getframerate ()
833- num_frames = wav_file .getnframes ()
834-
835- audio_content = wav_file .readframes (num_frames )
828+ audio_content , num_channels , sample_width , frame_rate = await asyncio .to_thread (self ._read_wav_file , filename )
836829
837830 receive_tasks = asyncio .create_task (self .receive_events_async (conversation_id = conversation_id ))
838831
@@ -871,3 +864,23 @@ async def _construct_message_from_response_async(self, response: Any, request: A
871864 This implementation exists to satisfy the abstract base class requirement.
872865 """
873866 raise NotImplementedError ("RealtimeTarget uses receive_events for message construction" )
867+
868+ @staticmethod
869+ def _read_wav_file (filename : str ) -> tuple [bytes , int , int , int ]:
870+ """
871+ Read raw audio frames and format metadata from a WAV file.
872+
873+ Args:
874+ filename (str): Path to the WAV file to read.
875+
876+ Returns:
877+ tuple[bytes, int, int, int]: The raw audio frames, number of channels,
878+ sample width in bytes, and frame rate.
879+ """
880+ with wave .open (filename , "rb" ) as wav_file :
881+ return (
882+ wav_file .readframes (wav_file .getnframes ()),
883+ wav_file .getnchannels (),
884+ wav_file .getsampwidth (),
885+ wav_file .getframerate (),
886+ )
0 commit comments