@@ -122,7 +122,7 @@ def generate_speech(self, text, voice_name):
122122
123123 data = {
124124 "text" : text ,
125- "model_id" : "eleven_monolingual_v1 " ,
125+ "model_id" : "eleven_turbo_v2_5 " ,
126126 "voice_settings" : {
127127 "stability" : 0.5 ,
128128 "similarity_boost" : 0.5
@@ -189,6 +189,8 @@ def play_on_robot(self, wav_data):
189189 start_req .binary = []
190190
191191 self .audio_pub .publish (start_req )
192+
193+ time .sleep (1 )
192194
193195 # Send WAV data in chunks
194196 for chunk_idx , chunk in enumerate (chunks , 1 ):
@@ -206,13 +208,22 @@ def play_on_robot(self, wav_data):
206208 }
207209 wav_req .parameter = json .dumps (audio_block )
208210 wav_req .binary = []
209-
211+
210212 self .audio_pub .publish (wav_req )
211213 self .get_logger ().info (f'Sent chunk { chunk_idx } /{ total_chunks } ({ len (chunk )} bytes)' )
212214
213215 # Add a small delay between chunks to prevent flooding
214216 time .sleep (0.01 )
215217
218+ # Wait until playback finished
219+ audio = AudioSegment .from_wav (io .BytesIO (wav_data ))
220+ duration_ms = len (audio )
221+ duration_s = duration_ms / 1000.0
222+
223+ self .get_logger ().info (f'Waiting for audio playback ({ duration_s :.2f} seconds)...' )
224+ time .sleep (duration_s )
225+
226+
216227 # End audio
217228 end_req = Request ()
218229 end_req .header .identity .id = identity
@@ -243,4 +254,4 @@ def main(args=None):
243254 rclpy .shutdown ()
244255
245256if __name__ == '__main__' :
246- main ()
257+ main ()
0 commit comments