mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-12-16 10:05:03 -05:00
Web viewer: cleanup TTS config dialog
This commit is contained in:
parent
81d16882bf
commit
6d4ba8aa0d
@ -245,7 +245,6 @@ class Client:
|
|||||||
voice_id = unique_id()
|
voice_id = unique_id()
|
||||||
rate_id = unique_id()
|
rate_id = unique_id()
|
||||||
select_id = unique_id()
|
select_id = unique_id()
|
||||||
default_voice = None
|
|
||||||
sd = get_session_data()
|
sd = get_session_data()
|
||||||
current_bar_pos = sd.get('tts_bar_position')
|
current_bar_pos = sd.get('tts_bar_position')
|
||||||
|
|
||||||
@ -255,7 +254,6 @@ class Client:
|
|||||||
document.getElementById(select_id).value = session_defaults().tts_bar_position
|
document.getElementById(select_id).value = session_defaults().tts_bar_position
|
||||||
|
|
||||||
create_custom_dialog(_('Configure Text-to-Speech'), def (parent_div, close_modal):
|
create_custom_dialog(_('Configure Text-to-Speech'), def (parent_div, close_modal):
|
||||||
nonlocal default_voice
|
|
||||||
pos_select = E.select(id=select_id)
|
pos_select = E.select(id=select_id)
|
||||||
|
|
||||||
def apos(text, name):
|
def apos(text, name):
|
||||||
@ -278,22 +276,28 @@ class Client:
|
|||||||
b = b.name.toLowerCase()
|
b = b.name.toLowerCase()
|
||||||
return -1 if a < b else (0 if a is b else 1)
|
return -1 if a < b else (0 if a is b else 1)
|
||||||
)
|
)
|
||||||
|
seen = {}
|
||||||
for voice in voices:
|
for voice in voices:
|
||||||
dflt = ''
|
if not seen[voice.voiceURI]:
|
||||||
if voice.default:
|
cloud = ''
|
||||||
default_voice = voice.voiceURI
|
if not voice.localService:
|
||||||
dflt = '-- {}'.format(_('default'))
|
cloud = ' -- ' + _('cloud based')
|
||||||
option = E.option(f'{voice.name} ({voice.lang}){dflt}', value=voice.voiceURI)
|
option = E.option(f'{voice.name} ({voice.lang}){cloud}', value=voice.voiceURI)
|
||||||
if (self.current_voice_uri and voice.voiceURI is self.current_voice_uri) or (not self.current_voice_uri and voice.default):
|
if self.current_voice_uri and voice.voiceURI is self.current_voice_uri:
|
||||||
option.setAttribute('selected', 'selected')
|
option.setAttribute('selected', 'selected')
|
||||||
select.appendChild(option)
|
select.appendChild(option)
|
||||||
parent_div.appendChild(E.div(_('Speed of speech:')))
|
seen[voice.voiceURI] = True
|
||||||
parent_div.appendChild(E.input(type='range', id=rate_id, min=(self.min_rate * 10) + '', max=(self.max_rate * 10) + '', value=((self.current_rate or 1) * 10) + ''))
|
if len(voices) < 1:
|
||||||
parent_div.appendChild(E.div(_('Pick a voice below:')))
|
select.appendChild(E.option(_('No voices available')))
|
||||||
parent_div.appendChild(select)
|
select.lastChild.disabled = True
|
||||||
|
parent_div.appendChild(E.div(_('Speed of speech:') + '\xa0'))
|
||||||
|
parent_div.lastChild.appendChild(
|
||||||
|
E.input(type='range', id=rate_id, min=(self.min_rate * 10) + '', max=(self.max_rate * 10) + '', value=((self.current_rate or 1) * 10) + ''))
|
||||||
|
parent_div.appendChild(E.div(_('Voice:') + '\xa0'))
|
||||||
|
parent_div.lastChild.appendChild(select)
|
||||||
if select.options.selectedIndex? and select.options[select.options.selectedIndex]:
|
if select.options.selectedIndex? and select.options[select.options.selectedIndex]:
|
||||||
select.options[select.options.selectedIndex].scrollIntoView()
|
select.options[select.options.selectedIndex].scrollIntoView()
|
||||||
parent_div.appendChild(E.div(_('Position of control bar:') + '\xa0', pos_select, style='margin-top: 1rem'))
|
parent_div.appendChild(E.div(_('Position of bar:') + '\xa0', pos_select, style='margin-top: 1rem'))
|
||||||
parent_div.appendChild(E.div(
|
parent_div.appendChild(E.div(
|
||||||
style='margin: 1rem; display: flex; justify-content: space-between; align-items: flex-start',
|
style='margin: 1rem; display: flex; justify-content: space-between; align-items: flex-start',
|
||||||
create_button(_('Restore defaults'), action=restore_defaults),
|
create_button(_('Restore defaults'), action=restore_defaults),
|
||||||
@ -301,13 +305,11 @@ class Client:
|
|||||||
))
|
))
|
||||||
|
|
||||||
, on_close=def():
|
, on_close=def():
|
||||||
voice = document.getElementById(voice_id).value
|
voice = document.getElementById(voice_id).value or ''
|
||||||
bar_pos = document.getElementById(select_id).value
|
bar_pos = document.getElementById(select_id).value
|
||||||
rate = int(document.getElementById(rate_id).value) / 10
|
rate = int(document.getElementById(rate_id).value) / 10
|
||||||
if rate is 1:
|
if rate is 1:
|
||||||
rate = None
|
rate = None
|
||||||
if voice is default_voice:
|
|
||||||
voice = ''
|
|
||||||
changed = voice is not self.current_voice_uri or rate is not self.current_rate or bar_pos is not current_bar_pos
|
changed = voice is not self.current_voice_uri or rate is not self.current_rate or bar_pos is not current_bar_pos
|
||||||
if changed:
|
if changed:
|
||||||
self.current_voice_uri = voice
|
self.current_voice_uri = voice
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user