@@ -133,16 +133,16 @@ async def record_audio(self, silence_cutoff_length_in_seconds: Optional[int] = 3
133133 await self .frame .bluetooth .send_lua (f"microphoneRecordAndSend({ self .sample_rate } ,{ self .bit_depth } ,nil)" )
134134 try :
135135 await asyncio .wait_for (self ._audio_finished_event .wait (), timeout = max_length_in_seconds )
136+ await self .frame .bluetooth .send_break_signal ()
136137 # Trim the final _silence_cutoff_length_in_seconds seconds
137138 trim_length = (self ._silence_cutoff_length_in_seconds - 0.5 ) * self ._sample_rate
138139 if len (self ._audio_buffer ) > trim_length :
139140 self ._audio_buffer = self ._audio_buffer [:- int (trim_length )]
140141 except asyncio .TimeoutError :
141- pass
142+ await self . frame . bluetooth . send_break_signal ()
142143 if self .frame .bluetooth .print_debugging :
143144 print (f"\n Audio recording finished with { len (self ._audio_buffer )/ self ._sample_rate :1.1f} seconds of audio" )
144145 self .frame .bluetooth .register_data_response_handler (FrameDataTypePrefixes .MIC_DATA , None )
145- await self .frame .bluetooth .send_break_signal ()
146146 await self .frame .run_lua ("frame.microphone.stop()" )
147147
148148 return self ._audio_buffer
@@ -169,9 +169,9 @@ async def save_audio_file(self, filename: str, silence_cutoff_length_in_seconds:
169169 audio_data = np .int16 (audio_data )
170170
171171 # based on the max and min values, normalize the data to be within the range of int16.min and int16.max.
172- real_range = np .max (audio_data ) - np .min (audio_data )
173- ideal_range = np .iinfo (np .int16 ).max - np .iinfo (np .int16 ).min
174- scale_factor = np .min ([ideal_range / real_range , np .iinfo (np .int16 ).max / np .max (audio_data ), np .iinfo (np .int16 ).min / np .min (audio_data )])
172+ real_range = int ( np .max (audio_data )) - int ( np .min (audio_data ) )
173+ ideal_range = int ( np .iinfo (np .int16 ).max ) - int ( np .iinfo (np .int16 ).min )
174+ scale_factor = np .min ([ideal_range / real_range , int ( np .iinfo (np .int16 ).max ) / np .max (audio_data ), int ( np .iinfo (np .int16 ).min ) / np .min (audio_data )])
175175 audio_data = (audio_data * scale_factor ).astype (np .int16 )
176176
177177 with wave .open (filename ,"wb" ) as f :
0 commit comments