addes speed config for voice
This commit is contained in:
+10
-1
@@ -38,6 +38,7 @@ import websockets
|
||||
from faster_whisper import WhisperModel
|
||||
from openwakeword.model import Model as WakeWordModel
|
||||
from piper import PiperVoice
|
||||
from piper.config import SynthesisConfig
|
||||
|
||||
from modes import Mode, detect_mode_switch, should_speak
|
||||
|
||||
@@ -131,6 +132,7 @@ class VoiceEngine:
|
||||
self.voices: dict[str, PiperVoice] = {}
|
||||
self.default_voice = "ramona"
|
||||
self.highlight_voice = "thorsten"
|
||||
self.speech_speed = 1.0 # 0.5 = langsam, 1.0 = normal, 2.0 = schnell
|
||||
|
||||
def initialize(self) -> None:
|
||||
"""Laedt die Piper-Stimmen aus dem Voices-Verzeichnis."""
|
||||
@@ -216,8 +218,9 @@ class VoiceEngine:
|
||||
continue
|
||||
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
|
||||
tmp_path = tmp.name
|
||||
syn_config = SynthesisConfig(length_scale=1.0 / max(0.3, self.speech_speed))
|
||||
with wave.open(tmp_path, "wb") as wav_file:
|
||||
voice.synthesize_wav(sentence, wav_file)
|
||||
voice.synthesize_wav(sentence, wav_file, syn_config=syn_config)
|
||||
with wave.open(tmp_path, "rb") as wav_file:
|
||||
if sample_rate is None:
|
||||
sample_rate = wav_file.getframerate()
|
||||
@@ -494,6 +497,7 @@ class ARIABridge:
|
||||
vc = json.load(f)
|
||||
self.voice_engine.default_voice = vc.get("defaultVoice", "ramona")
|
||||
self.voice_engine.highlight_voice = vc.get("highlightVoice", "thorsten")
|
||||
self.voice_engine.speech_speed = vc.get("speechSpeed", 1.0)
|
||||
self.tts_enabled = vc.get("ttsEnabled", True)
|
||||
logger.info("Voice-Config geladen: %s", vc)
|
||||
except Exception as e:
|
||||
@@ -1024,6 +1028,10 @@ class ARIABridge:
|
||||
self.tts_enabled = bool(payload["ttsEnabled"])
|
||||
logger.info("[rvs] TTS %s", "aktiviert" if self.tts_enabled else "deaktiviert")
|
||||
changed = True
|
||||
if "speechSpeed" in payload:
|
||||
self.voice_engine.speech_speed = max(0.3, min(2.0, float(payload["speechSpeed"])))
|
||||
logger.info("[rvs] Sprechgeschwindigkeit: %.1f", self.voice_engine.speech_speed)
|
||||
changed = True
|
||||
# Persistent speichern in Shared Volume
|
||||
if changed:
|
||||
try:
|
||||
@@ -1032,6 +1040,7 @@ class ARIABridge:
|
||||
"defaultVoice": self.voice_engine.default_voice,
|
||||
"highlightVoice": self.voice_engine.highlight_voice,
|
||||
"ttsEnabled": getattr(self, "tts_enabled", True),
|
||||
"speechSpeed": self.voice_engine.speech_speed,
|
||||
}
|
||||
with open("/shared/config/voice_config.json", "w") as f:
|
||||
json.dump(config_data, f, indent=2)
|
||||
|
||||
Reference in New Issue
Block a user