diff --git a/ghost.yaml b/ghost.yaml index f5dc4a2..95c4524 100644 --- a/ghost.yaml +++ b/ghost.yaml @@ -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' diff --git a/main.py b/main.py index 47d373c..ab50174 100644 --- a/main.py +++ b/main.py @@ -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) @@ -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() @@ -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")) @@ -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 @@ -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() diff --git a/tts.py b/tts.py deleted file mode 100644 index 30aaf0d..0000000 --- a/tts.py +++ /dev/null @@ -1,59 +0,0 @@ -# import pyttsx3 -# engine = pyttsx3.init() # object creation -# -# """ RATE""" -# rate = engine.getProperty('rate') # getting details of current speaking rate -# print (rate) #printing current voice rate -# engine.setProperty('rate', 125) # setting up new voice rate -# -# -# """VOLUME""" -# volume = engine.getProperty('volume') #getting to know current volume level (min=0 and max=1) -# print (volume) #printing current volume level -# engine.setProperty('volume',1.0) # setting up volume level between 0 and 1 -# -# """VOICE""" -# voices = engine.getProperty('voices') -# for voice in voices: -# print(voice) -# if voice.languages[0] == 'ru_RU': -# engine.setProperty('voice', voice.id) -# break - -#engine.setProperty('voice', voices[0].id) #changing index, changes voices. o for male -# engine.setProperty('voice', voices[1].id) #changing index, changes voices. 1 for female -# -# engine.say("Hello World!") -# engine.say('My current speaking rate is ' + str(rate)) -# engine.runAndWait() -# engine.stop() - -# https://pyttsx3.readthedocs.io/en/latest/engine.html#the-engine-factory - -import pyttsx3 -engine = pyttsx3.init() -voices = engine.getProperty('voices') - -rate = engine.getProperty('rate') # getting details of current speaking rate -print (rate) #printing current voice rate -engine.setProperty('rate', 150) # setting up new voice rate - -volume = engine.getProperty('volume') #getting to know current volume level (min=0 and max=1) -print (volume) #printing current volume level -engine.setProperty('volume',0.5) # setting up volume level between 0 and 1 - -index = 0 -for voice in voices: - print(f'index-> {index} -- {voice.name} -- {voice.id}') - index +=1 - - -engine.setProperty('voice', 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\Vocalizer Expressive milena premium-high 22kHz') -engine.startLoop() - -engine.say('Саша, пора уже ложиться!') -engine.runAndWait() -engine.stop() - - -# engine.runAndWait() \ No newline at end of file diff --git a/voice_plugin.py b/voice_plugin.py index b128a01..ae4f3c1 100644 --- a/voice_plugin.py +++ b/voice_plugin.py @@ -15,18 +15,6 @@ 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() @@ -34,14 +22,17 @@ def tick(self): 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('' + text + '') - self._engine.runAndWait() + if self.w.config['voice_enabled'].get(): + self._engine.say('' + text + '') + self._engine.runAndWait() time.sleep(0.1)