feat: wire effects into va_speak behind config.TTS_EFFECTS_ENABLED

This commit is contained in:
Bossiara13 2026-04-22 19:58:42 +03:00
parent bd6bc294ad
commit 64ad7b963e
2 changed files with 38 additions and 6 deletions

View file

@ -34,3 +34,10 @@ COMMAND_END_SILENCE_MS = 1200
COMMAND_MIN_SPEECH_MS = 500
COMMAND_MIN_LISTEN_MS = 1000
COMMAND_MAX_LISTEN_MS = 15000
TTS_EFFECTS_ENABLED = False
TTS_BANDPASS_LOW_HZ = 200
TTS_BANDPASS_HIGH_HZ = 7000
TTS_REVERB_WET = 0.20
TTS_REVERB_DECAY_MS = 100
TTS_PITCH_SEMITONES = 0

37
tts.py
View file

@ -1,8 +1,12 @@
import time
import numpy as np
import sounddevice as sd
import torch
import config
import effects
language = 'ru'
model_id = 'ru_v3'
sample_rate = 48000 # 48000
@ -19,18 +23,39 @@ model, _ = torch.hub.load(repo_or_dir='snakers4/silero-models',
model.to(device)
# воспроизводим
def va_speak(what: str):
def _post_process(audio):
if not getattr(config, 'TTS_EFFECTS_ENABLED', False):
return audio
arr = np.asarray(audio, dtype=np.float32)
low = getattr(config, 'TTS_BANDPASS_LOW_HZ', 0)
high = getattr(config, 'TTS_BANDPASS_HIGH_HZ', 0)
bandpass = (low, high) if low and high and high > low else None
wet = float(getattr(config, 'TTS_REVERB_WET', 0.0))
decay = int(getattr(config, 'TTS_REVERB_DECAY_MS', 0))
reverb = (wet, decay) if wet > 0 and decay > 0 else None
pitch = int(getattr(config, 'TTS_PITCH_SEMITONES', 0))
return effects.process(arr, sample_rate,
bandpass=bandpass,
reverb=reverb,
pitch_semitones=pitch)
def synthesize(what: str):
audio = model.apply_tts(text=what + "..",
speaker=speaker,
sample_rate=sample_rate,
put_accent=put_accent,
put_yo=put_yo)
return _post_process(audio)
def va_speak(what: str):
audio = synthesize(what)
sd.play(audio, sample_rate * 1.05)
time.sleep((len(audio) / sample_rate) + 0.5)
sd.stop()
# sd.play(audio, sample_rate)
# time.sleep(len(audio) / sample_rate)
# sd.stop()