Merge pull request #102 from pollen-robotics/fix/resample-overhead
Browse files
src/reachy_mini_conversation_app/console.py
CHANGED
|
@@ -8,8 +8,8 @@ import asyncio
|
|
| 8 |
import logging
|
| 9 |
from typing import List
|
| 10 |
|
| 11 |
-
import librosa
|
| 12 |
from fastrtc import AdditionalOutputs, audio_to_int16, audio_to_float32
|
|
|
|
| 13 |
|
| 14 |
from reachy_mini import ReachyMini
|
| 15 |
from reachy_mini_conversation_app.openai_realtime import OpenaiRealtimeHandler
|
|
@@ -30,6 +30,11 @@ class LocalStream:
|
|
| 30 |
# Allow the handler to flush the player queue when appropriate.
|
| 31 |
self.handler._clear_queue = self.clear_audio_queue
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
def launch(self) -> None:
|
| 34 |
"""Start the recorder/player and run the async processing loops."""
|
| 35 |
self._stop_event.clear()
|
|
@@ -110,7 +115,7 @@ class LocalStream:
|
|
| 110 |
audio_frame_float = audio_to_float32(audio_frame.squeeze())
|
| 111 |
|
| 112 |
if input_sample_rate != device_sample_rate:
|
| 113 |
-
audio_frame_float =
|
| 114 |
audio_frame_float,
|
| 115 |
orig_sr=input_sample_rate,
|
| 116 |
target_sr=device_sample_rate,
|
|
|
|
| 8 |
import logging
|
| 9 |
from typing import List
|
| 10 |
|
|
|
|
| 11 |
from fastrtc import AdditionalOutputs, audio_to_int16, audio_to_float32
|
| 12 |
+
from librosa import resample
|
| 13 |
|
| 14 |
from reachy_mini import ReachyMini
|
| 15 |
from reachy_mini_conversation_app.openai_realtime import OpenaiRealtimeHandler
|
|
|
|
| 30 |
# Allow the handler to flush the player queue when appropriate.
|
| 31 |
self.handler._clear_queue = self.clear_audio_queue
|
| 32 |
|
| 33 |
+
# Hack to avoid the first lenghty call to resample at runtime.
|
| 34 |
+
# This is likely caused by cache initialization overhead.
|
| 35 |
+
import numpy as np
|
| 36 |
+
resample(np.array([0.0]), orig_sr=1, target_sr=1)
|
| 37 |
+
|
| 38 |
def launch(self) -> None:
|
| 39 |
"""Start the recorder/player and run the async processing loops."""
|
| 40 |
self._stop_event.clear()
|
|
|
|
| 115 |
audio_frame_float = audio_to_float32(audio_frame.squeeze())
|
| 116 |
|
| 117 |
if input_sample_rate != device_sample_rate:
|
| 118 |
+
audio_frame_float = resample(
|
| 119 |
audio_frame_float,
|
| 120 |
orig_sr=input_sample_rate,
|
| 121 |
target_sr=device_sample_rate,
|