| 726 | pass |
| 727 | |
| 728 | async def accumulate_pcm_loop(): |
| 729 | nonlocal all_recorded_pcm |
| 730 | total_samples = 0 |
| 731 | last_all_recorded_pcm_id = id(all_recorded_pcm) if all_recorded_pcm is not None else None |
| 732 | |
| 733 | while True: |
| 734 | if close: |
| 735 | return |
| 736 | |
| 737 | current_id = id(all_recorded_pcm) if all_recorded_pcm is not None else None |
| 738 | if all_recorded_pcm is None and last_all_recorded_pcm_id is not None: |
| 739 | total_samples = 0 |
| 740 | log("info", "Reset PCM accumulator for new turn") |
| 741 | last_all_recorded_pcm_id = current_id |
| 742 | |
| 743 | # Read PCM data from the queue |
| 744 | try: |
| 745 | pcm = await asyncio.wait_for(pcm_queue.get(), timeout=0.01) |
| 746 | except asyncio.TimeoutError: |
| 747 | continue |
| 748 | |
| 749 | if pcm is None or len(pcm) == 0: |
| 750 | continue |
| 751 | |
| 752 | if is_recording: |
| 753 | pcm_samples = len(pcm) |
| 754 | total_samples += pcm_samples |
| 755 | log("info", f"Accumulating PCM: {pcm_samples} samples (total: {total_samples}, {total_samples/self.sample_rate:.2f}s)") |
| 756 | |
| 757 | if all_recorded_pcm is None: |
| 758 | all_recorded_pcm = pcm |
| 759 | else: |
| 760 | all_recorded_pcm = np.concatenate((all_recorded_pcm, pcm)) |
| 761 | |
| 762 | def tts_sender_thread_func(): |
| 763 | """[Multiprocessing] Send audio tokens to the TTS process""" |