Skip to content

Commit

Permalink
[stable] tts settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sakharovaan committed Nov 13, 2021
1 parent 3f90834 commit a44d536
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 81 deletions.
8 changes: 7 additions & 1 deletion ghost.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,10 @@ dialogue:
font: Consolas
size: 15
speed: 20
wait: 30000
wait: 15000

voice:
rate: 150
volume: 5
pitch: 5
voice: 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\Vocalizer Expressive milena premium-high 22kHz'
19 changes: 17 additions & 2 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from random_dialogue_plugin import RandomDialoguePlugin
from voice_plugin import VoicePlugin


class App(tk.Tk):
def __init__(self):
tk.Tk.__init__(self)
Expand All @@ -30,6 +31,12 @@ def __init__(self, *args, **kwargs):

self.grip = tk.Canvas(self, width=450+450, height=1000, background="brown", bd=0, highlightthickness=0, relief='ridge')

self.config = dict(
exit_initiated=False,
voice_enabled=tk.BooleanVar()
)
self.config['voice_enabled'].set(True)

self.dialogue_queue = queue.Queue()
self.voice_queue = queue.Queue()

Expand All @@ -43,7 +50,11 @@ def __init__(self, *args, **kwargs):
self.menu = tk.Menu(self, tearoff=0)
self.menu.add_command(label="Next expression", command=self.ep.random_tick)
self.menu.add_command(label="Show dialogue", command=self.rdp._say)
self.menu.add_checkbutton(label="add_checkbutton")

config_menu = tk.Menu(self.menu)
config_menu.add_checkbutton(label="Voice Enabled", onvalue=1, offvalue=0, variable=self.config['voice_enabled'])
self.menu.add_cascade(label='Configuration', menu=config_menu)

self.menu.add_separator()
self.menu.add_command(label="Exit", command=lambda: self.menu_callback("exit"))

Expand All @@ -68,7 +79,7 @@ def right_press(self, event):

def menu_callback(self, element):
if element == "exit":
self.app.destroy()
self.do_exit()
else:
raise

Expand All @@ -83,6 +94,10 @@ def do_move(self, event):
y = self.winfo_y() + deltay
self.geometry(f"+{x}+{y}")

def do_exit(self):
self.config['exit_initiated'] = True
self.app.destroy()


logging.basicConfig(level=logging.DEBUG)
app=App()
Expand Down
59 changes: 0 additions & 59 deletions tts.py

This file was deleted.

29 changes: 10 additions & 19 deletions voice_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,33 +15,24 @@ def __init__(self, window, _ghostconfig):
self._voice_thr = None
window.app.after(100, self.tick)

@staticmethod
def onStart(name):
print('starting ' + name)

@staticmethod
def onWord(name, location, length):
print('word ' + name + location + length)

@staticmethod
def onEnd(name, completed):
print('finishing ' + name + completed)

def tick(self):
self._voice_thr = threading.Thread(target=self._thread)
self._voice_thr.start()

def _thread(self):
self._engine = pyttsx3.init()

self._engine.setProperty('rate', 150)
self._engine.setProperty('volume', 0.5)
self._engine.setProperty('voice',
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\Vocalizer Expressive milena premium-high 22kHz')
for voice in self._engine.getProperty('voices'):
logging.debug('index-> ' + voice.name + ' ' + voice.id)

self._engine.setProperty('rate', self._config['voice']['rate'])
self._engine.setProperty('volume', self._config['voice']['volume'] / 10)
self._engine.setProperty('voice', self._config['voice']['voice'])

while True:
while not self.w.config['exit_initiated']:
if not self.w.voice_queue.empty():
text = self.w.voice_queue.get(block=False)
self._engine.say('<pitch middle="5">' + text + '</pitch>')
self._engine.runAndWait()
if self.w.config['voice_enabled'].get():
self._engine.say('<pitch middle="' + str(self._config['voice']['pitch']) + '">' + text + '</pitch>')
self._engine.runAndWait()
time.sleep(0.1)

0 comments on commit a44d536

Please sign in to comment.