F4b : suppression du code devenu inutile (VAD, diarisation, voix, mot de réveil, écoute continue)

Serveur : modules voice_activity, diarization, speaker_identifier, speaker_attribution,
wake_word et hands_free avec leurs tests ; sections vad, diarization, speaker et wake de
config.yaml ; horodatage des mots de Whisper ; extras diarization et wakeword ; HF_TOKEN.
__main__.py ne branche plus d'écoute mains libres.

Outils : vad_check, diarize_check et enroll supprimés ; speech_check sans VAD, say sans mot
de réveil, download_models limité à Whisper et Piper, latency_check réécrit (temps de Whisper
sur la session entière). Makefile : cibles et variables correspondantes retirées.

Firmware : commandes listen et capture, flux audio/stream, LED d'écoute continue supprimés ;
la LED au repos clignote lentement ; l'absence du serveur est seulement journalisée.
mosquitto/acl : droit d'écriture audio/stream retiré.

Les profils vocaux (server/profiles) et les modèles inutilisés ne sont pas touchés.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Denis Defolie
2026-10-18 14:07:44 +02:00
parent 6e432be805
commit 254fc093e5
37 changed files with 198 additions and 2901 deletions
+4 -76
View File
@@ -15,7 +15,6 @@ from voice_server.audio_resampler import AudioResampler, peak_dbfs
from voice_server.settings import Settings, load_settings
from voice_server.speech_to_text import SpeechToText
from voice_server.text_to_speech import TextToSpeech
from voice_server.voice_activity import VoiceActivityDetector
SETTINGS: Settings = load_settings(Path(__file__).resolve().parents[1] / "config.yaml")
@@ -58,77 +57,13 @@ def test_noise_hallucination_is_dropped(stt: SpeechToText) -> None:
assert "amara" not in stt.transcribe(noise).text.lower()
def test_vad_finds_speech_between_silences(tts: TextToSpeech) -> None:
"""1 s de silence, une phrase, 1 s de silence : la VAD retrouve la phrase et retire le reste."""
speech = tts.synthesize("Quelle heure est-il ?")
def test_speech_between_silences_is_transcribed_without_vad(tts: TextToSpeech, stt: SpeechToText) -> None:
"""F4, sans VAD : 1 s de silence avant (l'identification du doigt), la phrase, 1 s après (le retrait)."""
silence = bytes(32000)
detector = VoiceActivityDetector(SETTINGS.vad, SETTINGS.audio.sample_rate)
result = detector.detect(silence + speech.pcm + silence)
transcript = stt.transcribe(silence + tts.synthesize("Quelle heure est-il ?").pcm + silence)
assert result.has_speech
start = result.segments[0].start / 16000
end = result.segments[-1].end / 16000
assert 0.7 < start < 1.2 # début de parole, marge comprise
assert 1.0 + speech.audio_s - 0.4 < end < 1.0 + speech.audio_s + 0.3
assert result.speech_s < speech.audio_s + 0.5 # les 2 s de silence sont parties
def test_words_have_increasing_times(tts: TextToSpeech, stt: SpeechToText) -> None:
"""Étape 10 : chaque mot a un instant, dans l'ordre, et les mots recomposent le texte."""
transcript = stt.transcribe(tts.synthesize("Ferme les volets de la cuisine.").pcm)
assert len(transcript.words) >= 5
starts = [word.start_s for word in transcript.words]
assert starts == sorted(starts)
assert "".join(word.text for word in transcript.words).strip() == transcript.text
WAKE_READY = all((SETTINGS.wake.model_dir / name).exists()
for name in ("melspectrogram.onnx", "embedding_model.onnx", "alexa_v0.1.onnx"))
@pytest.mark.skipif(not WAKE_READY, reason="modeles openWakeWord absents : 'make models'")
def test_alexa_is_detected_and_silence_is_not(tts: TextToSpeech) -> None:
"""Étape 13 : « Alexa » dit par Piper déclenche ; le silence et une phrase ordinaire non."""
pytest.importorskip("openwakeword")
from voice_server.wake_word import WakeWordDetector
def first_detection(pcm: bytes) -> str | None:
detector = WakeWordDetector(SETTINGS.wake)
padded = bytes(32000) + pcm + bytes(32000)
for start in range(0, len(padded) - 1599, 1600):
detection = detector.process(padded[start:start + 1600])
if detection is not None:
return detection.word
return None
loud = AudioResampler(SETTINGS.audio, -10.0)
speaker = TextToSpeech(SETTINGS.tts, loud, SETTINGS.audio.sample_rate)
assert first_detection(speaker.synthesize("Alexa, allume la lumière.").pcm) == "alexa"
assert first_detection(speaker.synthesize("Bonjour, quelle heure est-il ?").pcm) is None
assert first_detection(bytes(64000)) is None
@pytest.mark.skipif(not WAKE_READY, reason="modeles openWakeWord absents : 'make models'")
def test_per_word_threshold_and_near_miss(caplog: pytest.LogCaptureFixture, tts: TextToSpeech) -> None:
"""Un seuil propre au mot ; sous le seuil, le pic est journalisé comme « presque reconnu »."""
pytest.importorskip("openwakeword")
import dataclasses
import logging
from voice_server.wake_word import WakeWordDetector
strict = dataclasses.replace(SETTINGS.wake, thresholds={"alexa": 1.01}) # inatteignable
detector = WakeWordDetector(strict, "esp32-test")
speaker = TextToSpeech(SETTINGS.tts, AudioResampler(SETTINGS.audio, -10.0), SETTINGS.audio.sample_rate)
padded = bytes(32000) + speaker.synthesize("Alexa, allume la lumière.").pcm + bytes(64000)
with caplog.at_level(logging.INFO, logger="voice_server.wake_word"):
found = [detector.process(padded[i:i + 1600]) for i in range(0, len(padded) - 1599, 1600)]
assert all(detection is None for detection in found)
assert "presque reconnu « alexa »" in caplog.text
assert "heure" in transcript.text.lower()
def test_repeated_answer_comes_from_the_cache(tts: TextToSpeech) -> None:
@@ -149,10 +84,3 @@ def test_cache_keeps_a_bounded_number_of_answers(tts: TextToSpeech, monkeypatch:
fresh.synthesize(text)
assert fresh.synthesize("Trois.").elapsed_s < 0.005 # encore en mémoire
assert fresh.synthesize("Un.").elapsed_s > 0.005 # la plus ancienne est sortie
def test_transcription_without_word_times(tts: TextToSpeech, stt: SpeechToText) -> None:
"""Étape 16 : sans horodatage des mots, même texte, pas de mots."""
pcm = tts.synthesize("Fermez la porte du garage.").pcm
plain = stt.transcribe(pcm, words=False)
assert plain.words == () and "garage" in plain.text.lower()