You've already forked Irene-Voice-Assistant
mirror of
https://github.com/janvarev/Irene-Voice-Assistant.git
synced 2025-11-26 22:50:58 +02:00
Возможность кэширования wav файлов, создаваемых TTS движком
Добавлена опция useTTSCache, при значении true будет кэшировать ответы в папке tts_cache Примеры, почему это может быть полезно: - повышения скорости ответа ассистента, запущенного на слабом железе - воспроизведение заранее закешированных на другом устройстве ответов TTS движка silero v3 на устройстве, не поддерживающем AVX2 инструкции и потому не позволяющем использовать этот TTS движок
This commit is contained in:
@@ -80,6 +80,7 @@ https://github.com/timhok/IreneVA-hassio-script-trigger-plugin
|
||||
"mpcHcPath": "C:\\Program Files (x86)\\K-Lite Codec Pack\\MPC-HC64\\mpc-hc64_nvo.exe", # путь до MPC HC, если используете
|
||||
"mpcIsUse": true, # используется ли MPC HC?
|
||||
"mpcIsUseHttpRemote": true, # MPC HC - включено ли управление через веб-интерфейс?
|
||||
"useTTSCache": false, # при установке true в папке tts_cache будет кэшировать .wav файлы со сгенерированными TTS-движком ответами
|
||||
"ttsEngineId": "pyttsx", # используемый TTS-движок
|
||||
"v": "1.7", # версия плагина core. Обновляется автоматически, не трогайте
|
||||
"voiceAssNames": "ирина|ирины|ирину" # Если это появится в звуковом потоке, то дальше будет команда. (Различные имена помощника, рекомендуется несколько)
|
||||
|
||||
@@ -16,6 +16,7 @@ def start(core:VACore):
|
||||
|
||||
"isOnline": False,
|
||||
#"ttsIndex": 0,
|
||||
"useTTSCache": False,
|
||||
"ttsEngineId": "pyttsx",
|
||||
"ttsEngineId2": "", # двиг для прямой озвучки на сервере. Если пуст - используется ttsEngineId
|
||||
"playWavEngineId": "audioplayer",
|
||||
@@ -54,6 +55,11 @@ def start_with_options(core:VACore, manifest:dict):
|
||||
if not os.path.exists(core.tmpdir):
|
||||
os.mkdir(core.tmpdir)
|
||||
|
||||
core.useTTSCache = options["useTTSCache"]
|
||||
core.tts_cache_dir = "tts_cache"
|
||||
if not os.path.exists(core.tts_cache_dir):
|
||||
os.mkdir(core.tts_cache_dir)
|
||||
|
||||
import lingua_franca
|
||||
lingua_franca.load_language(options["linguaFrancaLang"])
|
||||
|
||||
|
||||
43
vacore.py
43
vacore.py
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
import traceback
|
||||
import hashlib
|
||||
|
||||
import time
|
||||
from threading import Timer
|
||||
@@ -38,6 +39,8 @@ class VACore(JaaCore):
|
||||
|
||||
self.voiceAssNames = []
|
||||
|
||||
self.useTTSCache = False
|
||||
self.tts_cache_dir = "tts_cache"
|
||||
self.ttsEngineId = ""
|
||||
self.ttsEngineId2 = ""
|
||||
self.playWavEngineId = ""
|
||||
@@ -128,28 +131,38 @@ class VACore(JaaCore):
|
||||
if self.ttss[self.ttsEngineId][1] != None:
|
||||
self.ttss[self.ttsEngineId][1](self,text_to_speech)
|
||||
else:
|
||||
tempfilename = self.get_tempfilename()+".wav"
|
||||
#print('Temp TTS filename: ', tempfilename)
|
||||
self.tts_to_filewav(text_to_speech,tempfilename)
|
||||
self.play_wav(tempfilename)
|
||||
if os.path.exists(tempfilename):
|
||||
os.unlink(tempfilename)
|
||||
if self.useTTSCache:
|
||||
tts_file = self.get_tts_cache_file(text_to_speech)
|
||||
else:
|
||||
tts_file = self.get_tempfilename()+".wav"
|
||||
|
||||
#print('Temp TTS filename: ', tts_file)
|
||||
if not self.useTTSCache or self.useTTSCache and not os.path.exists(tts_file):
|
||||
self.tts_to_filewav(text_to_speech, tts_file)
|
||||
|
||||
self.play_wav(tts_file)
|
||||
if not self.useTTSCache and os.path.exists(tts_file):
|
||||
os.unlink(tts_file)
|
||||
|
||||
if "saytxt" in remoteTTSList: # return only last say txt
|
||||
self.remoteTTSResult["restxt"] = text_to_speech
|
||||
|
||||
if "saywav" in remoteTTSList:
|
||||
tempfilename = self.get_tempfilename()+".wav"
|
||||
if self.useTTSCache:
|
||||
tts_file = self.get_tts_cache_file(text_to_speech)
|
||||
else:
|
||||
tts_file = self.get_tempfilename()+".wav"
|
||||
|
||||
self.tts_to_filewav(text_to_speech,tempfilename)
|
||||
#self.play_wav(tempfilename)
|
||||
if not self.useTTSCache or self.useTTSCache and not os.path.exists(tts_file):
|
||||
self.tts_to_filewav(text_to_speech, tts_file)
|
||||
#self.play_wav(tts_file)
|
||||
import base64
|
||||
|
||||
with open(tempfilename, "rb") as wav_file:
|
||||
with open(tts_file, "rb") as wav_file:
|
||||
encoded_string = base64.b64encode(wav_file.read())
|
||||
|
||||
if os.path.exists(tempfilename):
|
||||
os.unlink(tempfilename)
|
||||
if not self.useTTSCache and os.path.exists(tts_file):
|
||||
os.unlink(tts_file)
|
||||
|
||||
self.remoteTTSResult = {"wav_base64":encoded_string}
|
||||
|
||||
@@ -185,6 +198,12 @@ class VACore(JaaCore):
|
||||
self.tmpcnt += 1
|
||||
return self.tmpdir+"/vacore_"+str(self.tmpcnt)
|
||||
|
||||
def get_tts_cache_file(self, text_to_speech:str):
|
||||
hash = hashlib.md5(text_to_speech.encode('utf-8')).hexdigest()
|
||||
text_slice = text_to_speech[:80]
|
||||
filename = ".".join([text_slice, hash, "wav"])
|
||||
return self.tts_cache_dir+"/"+filename
|
||||
|
||||
def all_num_to_text(self,text:str):
|
||||
from utils.all_num_to_text import all_num_to_text
|
||||
return all_num_to_text(text)
|
||||
|
||||
Reference in New Issue
Block a user