2023-04-07 20:42:20 +02:00
|
|
|
# TTS plugin for Vosk engine
|
|
|
|
|
# author: Vladislav Janvarev
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
from vacore import VACore
|
2023-04-08 01:17:52 +03:00
|
|
|
from vosk_tts.model import Model
|
|
|
|
|
from vosk_tts.synth import Synth
|
2023-04-07 20:42:20 +02:00
|
|
|
|
|
|
|
|
modname = os.path.basename(__file__)[:-3] # calculating modname
|
|
|
|
|
|
|
|
|
|
# функция на старте
|
|
|
|
|
def start(core:VACore):
|
|
|
|
|
manifest = {
|
|
|
|
|
"name": "TTS vosk",
|
|
|
|
|
"version": "1.1",
|
|
|
|
|
"require_online": False,
|
|
|
|
|
|
2023-05-11 16:45:47 +03:00
|
|
|
"description": "TTS через VOSK\n"
|
|
|
|
|
"ID для указания: vosk\n"
|
2023-05-11 17:46:22 +03:00
|
|
|
"Список голосов доступен здесь: https://giters.com/alphacep/vosk-tts",
|
2023-05-11 16:45:47 +03:00
|
|
|
|
2023-04-07 20:42:20 +02:00
|
|
|
"default_options": {
|
2023-04-12 10:55:29 +03:00
|
|
|
"voiceId": "vosk-model-tts-ru-0.1-irina", # id голоса
|
|
|
|
|
# vosk-model-tts-ru-0.1-natasha
|
2023-04-07 20:42:20 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
"tts": {
|
2023-04-08 01:17:52 +03:00
|
|
|
"vosk": (init,None,towavfile) # первая функция инициализации, вторая - говорить, третья - в wav file
|
2023-04-07 20:42:20 +02:00
|
|
|
# если вторая - None, то используется 3-я с проигрыванием файла
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return manifest
|
|
|
|
|
|
|
|
|
|
def start_with_options(core:VACore, manifest:dict):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
def init(core:VACore):
|
|
|
|
|
options = core.plugin_options(modname)
|
|
|
|
|
|
2023-04-08 01:17:52 +03:00
|
|
|
core.ttsModel = Model(model_name = options['voiceId'])
|
|
|
|
|
core.ttsSynth = Synth(core.ttsModel)
|
2023-04-07 20:42:20 +02:00
|
|
|
|
|
|
|
|
def towavfile(core:VACore, text_to_speech:str,wavfile:str):
|
|
|
|
|
"""
|
|
|
|
|
Проигрывание речи ответов голосового ассистента с сохранением в файл
|
|
|
|
|
:param text_to_speech: текст, который нужно преобразовать в речь
|
|
|
|
|
"""
|
|
|
|
|
core.ttsSynth.synth(text_to_speech,wavfile)
|