Spaces:
Configuration error
Configuration error
from vits_tts import tts | |
import winsound | |
import threading | |
import time | |
def PlaySound(filename): | |
winsound.PlaySound(filename, winsound.SND_FILENAME) | |
def Play(text, notify, cb_before_play, args): | |
if cb_before_play != None: | |
cb_before_play(*args) | |
result, wav = tts.GenerateTTS(text) | |
if result == True: | |
if notify != None: | |
PlaySound(f"{notify}") | |
PlaySound(wav) | |
class DmPlayer: | |
def __init__(self): | |
self.pending_list = [] | |
self.playing = False | |
def Pend(self, text, notify = None, cb_before_play = None, *args): | |
self.pending_list.append((text, notify, cb_before_play, args)) | |
if self.playing == False: | |
self.playing = True | |
threading.Thread(target=self.Play, args=()).start() | |
def Play(self): | |
try: | |
(text, notify, cb_before_play, args) = self.pending_list.pop(0) | |
except: | |
self.playing = False | |
print('Queue empty') | |
else: | |
Play(text, notify, cb_before_play, args) | |
time.sleep(0.5) | |
self.Play() | |
def LoadCharacter(self, name): | |
tts.LoadCharacter(name) | |
# ns "控制感情变化程度", minimum=0.1, maximum=1.0 | |
# nsw "控制音素发音长度", minimum=0.1, maximum=1.0 | |
# ls "控制整体语速", minimum=0.1, maximum=2.0 | |
def SetVoiceOption(self, ns, nsw, ls): | |
tts.SetVoiceOption(ns, nsw, ls) |