Skip to content

Commit 4ea3989

Browse files
committed
Adding behaviour on no voices found
- Warning user to download voices if no voices found, and closing Hear2Read if no voices found - Correcting bug where pause and synth change were not working
1 parent 658f124 commit 4ea3989

File tree

6 files changed

+217
-109
lines changed

6 files changed

+217
-109
lines changed

globalPlugins/hear2readng_global_plugin/__init__.py

Lines changed: 51 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
import core
1414
import globalPluginHandler
1515
import gui
16+
import queueHandler
1617
import wx
18+
from gui.message import DisplayableError
1719
from logHandler import log
18-
from synthDriverHandler import getSynth, synthChanged
20+
from synthDriverHandler import findAndSetNextSynth, getSynth, synthChanged
1921

2022
from globalPlugins.hear2readng_global_plugin.english_settings import (
2123
EnglishSpeechSettingsDialog,
@@ -31,9 +33,16 @@ class GlobalPlugin(globalPluginHandler.GlobalPlugin):
3133
def __init__(self, *args, **kwargs):
3234
super().__init__(*args, **kwargs)
3335
self.__voice_manager_shown = False
36+
curr_synth_name = getSynth().name
3437
self._voice_checker = lambda: wx.CallLater(2000,
35-
self._perform_voice_check)
38+
self._perform_voice_check)
3639
core.postNvdaStartup.register(self._voice_checker)
40+
41+
# if "Hear2Read NG" not in curr_synth_name:
42+
# self._voice_checker = lambda: wx.CallLater(2000,
43+
# self._perform_voice_check)
44+
# core.postNvdaStartup.register(self._voice_checker)
45+
3746
self.itemHandle = gui.mainFrame.sysTrayIcon.menu.Insert(
3847
4,
3948
wx.ID_ANY,
@@ -45,14 +54,10 @@ def __init__(self, *args, **kwargs):
4554
gui.mainFrame.sysTrayIcon.menu.Bind(wx.EVT_MENU, self.on_manager,
4655
self.itemHandle)
4756

48-
# TODO make this work?
49-
# if "Hear2Read NG" not in getSynth().name:
50-
# return
51-
5257
self.eng_settings_active = False
5358
self.eng_settings_id = wx.Window.NewControlId()
5459

55-
if "Hear2Read NG" in getSynth().name:
60+
if "Hear2Read NG" in curr_synth_name:
5661
# self.eng_settings_id = wx.Window.NewControlId()
5762
self.make_eng_settings_menu()
5863
self.eng_settings_active = True
@@ -64,6 +69,7 @@ def on_synth_changed(self, synth):
6469
# self.eng_settings_id = wx.Window.NewControlId()
6570
self.make_eng_settings_menu()
6671
self.eng_settings_active = True
72+
self._perform_voice_check()
6773

6874
elif self.eng_settings_active:
6975
gui.mainFrame.sysTrayIcon.menu.Remove(self.eng_settings_id)
@@ -83,20 +89,43 @@ def make_eng_settings_menu(self):
8389
EnglishSpeechSettingsDialog),
8490
self.itemHandle)
8591

86-
def on_manager(self, event):
92+
def on_manager(self, event=None):
8793
manager_dialog = Hear2ReadNGVoiceManagerDialog()
8894
try:
89-
gui.runScriptModalDialog(manager_dialog)
95+
gui.runScriptModalDialog(manager_dialog, callback=self.on_manager_close)
9096
self.__voice_manager_shown = True
9197
except Exception as e:
9298
log.error(f"Failed to open Manager: {e}")
9399

94-
def _perform_voice_check(self):
95-
if self.__voice_manager_shown:
96-
return
97-
100+
def on_manager_close(self, res):
98101
if not any(Hear2ReadNGVoiceManagerDialog.get_installed_voices()):
102+
self.on_no_voices(getSynth().name)
99103

104+
def on_no_voices(self, curr_synth_name):
105+
106+
if "Hear2Read NG" in curr_synth_name:
107+
msg_res = gui.messageBox(
108+
# Translators: message telling the user that no voice is installed
109+
_(
110+
"No Indic Hear2Read voice was found.\n"
111+
"Please download a voice from the manager to continue using Hear2Read Synthesizer.\n"
112+
"Do you want to open the voice manager now?"
113+
),
114+
# Translators: title of a message telling the user that no Hear2Read Indic voice was found
115+
_("Hear2Read Indic Voices"),
116+
wx.YES_NO | wx.ICON_WARNING,)
117+
118+
if msg_res == wx.YES:
119+
wx.CallAfter(self.on_manager)
120+
else:
121+
noVoiceDisplayError = DisplayableError(
122+
titleMessage="Shutting Hear2Read Down",
123+
displayMessage="No Hear2Read voices found. \n"
124+
"Please install voices to use Hear2Read. \n"
125+
"Voices can be installed from the Hear2Read voice manager in the NVDA menu")
126+
noVoiceDisplayError.displayError(gui.mainFrame)
127+
queueHandler.queueFunction(queueHandler.eventQueue, findAndSetNextSynth, curr_synth_name)
128+
else:
100129
if wx.YES == gui.messageBox(
101130
# Translators: message telling the user that no voice is installed
102131
_(
@@ -107,9 +136,17 @@ def _perform_voice_check(self):
107136
# Translators: title of a message telling the user that no Hear2Read Indic voice was found
108137
_("Hear2Read Indic Voices"),
109138
wx.YES_NO | wx.ICON_WARNING,):
139+
wx.CallAfter(self.on_manager)
110140

111-
self.on_manager(None)
141+
# @gui.blockAction.when(gui.blockAction.Context.MODAL_DIALOG_OPEN)
142+
def _perform_voice_check(self):
143+
if self.__voice_manager_shown:# or gui.isModalMessageBoxActive():
144+
return
112145

146+
if not any(Hear2ReadNGVoiceManagerDialog.get_installed_voices()):
147+
curr_synth_name = getSynth().name
148+
# queueHandler.queueFunction(queueHandler.eventQueue, self.on_no_voices, curr_synth_name)
149+
self.on_no_voices(curr_synth_name)
113150

114151
def terminate(self):
115152
try:

globalPlugins/hear2readng_global_plugin/utils.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,28 @@
2121
H2RNG_WAVS_DIR,
2222
)
2323

24+
# H2RNG_DATA_DIR = os.path.join(os.getenv("APPDATA"), "Hear2Read-NG")
25+
# H2RNG_PHONEME_DIR = os.path.join(H2RNG_DATA_DIR, "espeak-ng-data")
26+
# H2RNG_ENGINE_DLL_PATH = os.path.join(H2RNG_DATA_DIR, "Hear2ReadNG_addon_engine.dll")
27+
# H2RNG_VOICES_DIR = os.path.join(H2RNG_DATA_DIR, "Voices")
28+
# H2RNG_WAVS_DIR = os.path.join(H2RNG_DATA_DIR, "wavs")
29+
# EN_VOICE_ALOK = "en_US-arctic-medium"
30+
31+
lang_names = {"as":"Assamese",
32+
"bn":"Bengali",
33+
"gu":"Gujarati",
34+
"hi":"Hindi",
35+
"kn":"Kannada",
36+
"ml":"Malayalam",
37+
"mr":"Marathi",
38+
"ne":"Nepali",
39+
"or":"Odia",
40+
"pa":"Punjabi",
41+
"si":"Sinhala",
42+
"ta":"Tamil",
43+
"te":"Telugu",
44+
"en":"English"}
45+
2446
try:
2547
_dir=os.path.dirname(__file__.decode("mbcs"))
2648
except AttributeError:
@@ -83,6 +105,34 @@ def check_files():
83105
# return dll_is_present and phonedir_is_present and voice_is_present
84106

85107

108+
def populateVoices():
109+
pathName = os.path.join(H2RNG_VOICES_DIR)
110+
voices = dict()
111+
#list all files in Language directory
112+
file_list = os.listdir(pathName)
113+
#FIXME: the english voice is obsolete, maybe remove the voiceid?
114+
en_voice = EN_VOICE_ALOK
115+
voices[en_voice] = "English"
116+
for file in file_list:
117+
list = file.split(".")
118+
if list[-1] == "onnx":
119+
if f"{file}.json" not in file_list:
120+
continue
121+
nameList = list[0].split("-")
122+
lang = nameList[0].split("_")[0]
123+
124+
# Already set the sole English voice
125+
if lang == "en":
126+
continue
127+
128+
language = lang_names.get(lang)
129+
if language:
130+
voices[list[0]] = language
131+
else:
132+
voices[list[0]] = f"Unknown language ({list[0]})"
133+
134+
return voices
135+
86136
def move_old_voices():
87137
"""Tries to move voices downloaded in addon version 1.4 and lower to the
88138
new dir structure to be usable by this addon. This is slightly different
@@ -140,6 +190,7 @@ def move_old_voices():
140190

141191
return voices_moved
142192

193+
# def show_voice_manager():
143194

144195
def onInstall():
145196
"""A fallback that tries moving the required data files in case it wasn't

globalPlugins/hear2readng_global_plugin/voice_manager.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@
1818
import wx
1919
from logHandler import log
2020

21-
from synthDrivers._H2R_NG_Speak import (
21+
from .utils import (
2222
H2RNG_DATA_DIR,
2323
H2RNG_VOICES_DIR,
24+
DownloadThread,
25+
Voice,
26+
check_files,
2427
lang_names,
28+
onInstall,
2529
populateVoices,
2630
)
2731

28-
from .utils import DownloadThread, Voice, check_files, onInstall
29-
3032
# Constants and global variables:
3133

3234
DLL_FILE_NAME_PREFIX = "Hear2ReadNG_addon_engine"

manifest.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "Hear2Read NG"
22
summary = "Hear2Read Indic Speech Synthesizer"
3-
version = "1.6.0"
3+
version = "1.6.1"
44
description = "This is a speech synthesizer for 11 Indic languages and English (with Indian accent) that generates natural human speech. It is based on the work done by the piper TTS team (https://github.com/rhasspy/piper). The addon includes a voice manager for installing one or more Indic voices. Supported languages: Assamese, Bengali, Gujarati, Hindi, Kannada, Malayalam, Nepali, Odia, Punjabi, Tamil, Telugu"
55
author = "Hear2Read Contributers<info@Hear2Read.org>"
66
url = "https://hear2read.org"

0 commit comments

Comments
 (0)