feature: 集成bert_vits

This commit is contained in:
killua committed 2024-06-24 11:02:42 +08:00
1 parent 2b98752db1
commit c58c7c9a5b
9 files changed
+69 -51

No files matched your search

+23 -3
View File
@@ -6,7 +6,8 @@ from .abstract import *
from .public import *
from .exception import *
from .dependency import get_logger
from utils.vits_utils import TextToSpeech
from utils.vits_utils import TextToSpeech as VITS_TextToSpeech
from utils.bert_vits2_utils import TextToSpeech as BertVits_TextToSpeech
from config import Config
import threading
import requests
@@ -17,7 +18,11 @@ import time
import json
# ----------- 初始化vits ----------- #
vits = TextToSpeech()
vits = VITS_TextToSpeech()
# ---------------------------------- #
# -------- 初始化bert-vits --------- #
bert_vits = BertVits_TextToSpeech()
# ---------------------------------- #
# ---------- 初始化logger ---------- #
@@ -294,6 +299,14 @@ class VITS_TTS(TTS):
def synthetize(self, assistant, text):
tts_info = json.loads(assistant.tts_info)
return vits.synthesize(text, tts_info)
class BertVits_TTS(TTS):
def __init__(self):
pass
def synthetize(self, assistant, text):
tts_info = json.loads(assistant.tts_info)
return bert_vits.synthesize(text, tts_info)
# --------------------------------- #
@@ -319,6 +332,8 @@ class TTSFactory:
def create_tts(self,tts_type:str) -> TTS:
if tts_type == 'VITS':
return VITS_TTS()
if tts_type == 'BertVits':
return BertVits_TTS()
# --------------------------------- #
@@ -420,7 +435,12 @@ class Agent():
self.tts_audio_service_chain.add_service(TTSAudioRecordService())
def init_recorder(self,user_id):
self.recorder = Recorder(user_id)
input_sr = 16000
if isinstance(self.tts, BertVits_TTS):
output_sr = 44100
elif isinstance(self.tts, VITS_TTS):
output_sr = 22050
self.recorder = Recorder(user_id,input_sr,output_sr)
# 对用户输入的音频进行预处理
def user_audio_process(self, audio):