Commit ·
faec4a4
1
Parent(s): 8d4f1ef
Restore scipy and soundfile dependencies
Browse filesReachy Mini media system requires these libraries for audio processing
- pyproject.toml +2 -0
- reachy_mini_ha_voice/app.py +23 -9
pyproject.toml
CHANGED
|
@@ -31,6 +31,8 @@ dependencies = [
|
|
| 31 |
"pyaudio>=0.2.11",
|
| 32 |
"zeroconf<1",
|
| 33 |
"reachy-mini",
|
|
|
|
|
|
|
| 34 |
]
|
| 35 |
|
| 36 |
[project.optional-dependencies]
|
|
|
|
| 31 |
"pyaudio>=0.2.11",
|
| 32 |
"zeroconf<1",
|
| 33 |
"reachy-mini",
|
| 34 |
+
"scipy",
|
| 35 |
+
"soundfile",
|
| 36 |
]
|
| 37 |
|
| 38 |
[project.optional-dependencies]
|
reachy_mini_ha_voice/app.py
CHANGED
|
@@ -320,16 +320,30 @@ class ReachyMiniAudioPlayer:
|
|
| 320 |
# Check if it's a URL or file path
|
| 321 |
if audio_source.startswith(('http://', 'https://')):
|
| 322 |
_LOGGER.info(f"Playing audio from URL: {audio_source}")
|
| 323 |
-
# For URLs,
|
| 324 |
-
|
| 325 |
else:
|
| 326 |
-
# Load audio file
|
| 327 |
-
|
| 328 |
-
|
| 329 |
-
|
| 330 |
-
#
|
| 331 |
-
|
| 332 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 333 |
|
| 334 |
if done_callback:
|
| 335 |
done_callback()
|
|
|
|
| 320 |
# Check if it's a URL or file path
|
| 321 |
if audio_source.startswith(('http://', 'https://')):
|
| 322 |
_LOGGER.info(f"Playing audio from URL: {audio_source}")
|
| 323 |
+
# For URLs, use Reachy Mini's play_sound method
|
| 324 |
+
self._robot.media.play_sound(audio_source)
|
| 325 |
else:
|
| 326 |
+
# Load audio file using soundfile
|
| 327 |
+
import soundfile as sf
|
| 328 |
+
data, sr = sf.read(audio_source, dtype='float32')
|
| 329 |
+
|
| 330 |
+
# Resample if needed
|
| 331 |
+
output_sr = self._robot.media.get_output_audio_samplerate()
|
| 332 |
+
if sr != output_sr:
|
| 333 |
+
from scipy.signal import resample
|
| 334 |
+
data = resample(data, int(len(data) * output_sr / sr))
|
| 335 |
+
|
| 336 |
+
# Ensure correct shape for output channels
|
| 337 |
+
output_channels = self._robot.media.get_output_channels()
|
| 338 |
+
if data.ndim == 1 and output_channels > 1:
|
| 339 |
+
data = np.tile(data[:, None], (1, output_channels))
|
| 340 |
+
elif data.ndim == 2 and data.shape[1] < output_channels:
|
| 341 |
+
data = np.tile(data[:, [0]], (1, output_channels))
|
| 342 |
+
elif data.ndim == 2 and data.shape[1] > output_channels:
|
| 343 |
+
data = data[:, :output_channels]
|
| 344 |
+
|
| 345 |
+
# Push to player
|
| 346 |
+
self._robot.media.push_audio_sample(data)
|
| 347 |
|
| 348 |
if done_callback:
|
| 349 |
done_callback()
|