formatting code

This commit is contained in:
lanvent
2023-04-17 01:00:08 +08:00
parent 3b8972ce1f
commit 8f72e8c3e6
92 changed files with 1850 additions and 1188 deletions

View File

@@ -1,10 +1,11 @@
"""
pytts voice service (offline)
"""
import time
import pyttsx3
from bridge.reply import Reply, ReplyType
from common.log import logger
from common.tmp_dir import TmpDir
@@ -16,20 +17,21 @@ class PyttsVoice(Voice):
def __init__(self):
# 语速
self.engine.setProperty('rate', 125)
self.engine.setProperty("rate", 125)
# 音量
self.engine.setProperty('volume', 1.0)
for voice in self.engine.getProperty('voices'):
self.engine.setProperty("volume", 1.0)
for voice in self.engine.getProperty("voices"):
if "Chinese" in voice.name:
self.engine.setProperty('voice', voice.id)
self.engine.setProperty("voice", voice.id)
def textToVoice(self, text):
try:
wavFile = TmpDir().path() + 'reply-' + str(int(time.time())) + '.wav'
wavFile = TmpDir().path() + "reply-" + str(int(time.time())) + ".wav"
self.engine.save_to_file(text, wavFile)
self.engine.runAndWait()
logger.info(
'[Pytts] textToVoice text={} voice file name={}'.format(text, wavFile))
"[Pytts] textToVoice text={} voice file name={}".format(text, wavFile)
)
reply = Reply(ReplyType.VOICE, wavFile)
except Exception as e:
reply = Reply(ReplyType.ERROR, str(e))