mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Get speaking rate changes working
This commit is contained in:
parent
c8e9f33736
commit
e872e7588b
@ -133,6 +133,7 @@ class Client:
|
|||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
self.backend.pause()
|
self.backend.pause()
|
||||||
|
self.synthesizing = False
|
||||||
self.clear_chunks()
|
self.clear_chunks()
|
||||||
if self.current_callback is not None:
|
if self.current_callback is not None:
|
||||||
self.current_callback(Event(EventType.cancel))
|
self.current_callback(Event(EventType.cancel))
|
||||||
@ -151,17 +152,17 @@ class Client:
|
|||||||
|
|
||||||
def apply_settings(self, new_settings=None):
|
def apply_settings(self, new_settings=None):
|
||||||
if self.synthesizing:
|
if self.synthesizing:
|
||||||
self.stop()
|
self.pause()
|
||||||
if new_settings is not None:
|
if new_settings is not None:
|
||||||
self.settings = new_settings
|
self.settings = new_settings
|
||||||
try:
|
|
||||||
self.backend.set_rate(self.settings.get('rate', self.default_system_rate))
|
|
||||||
except OSError:
|
|
||||||
self.settings.pop('rate', None)
|
|
||||||
try:
|
try:
|
||||||
self.backend.set_voice(self.settings.get('voice'), self.default_system_voice)
|
self.backend.set_voice(self.settings.get('voice'), self.default_system_voice)
|
||||||
except OSError:
|
except OSError:
|
||||||
self.settings.pop('voice', None)
|
self.settings.pop('voice', None)
|
||||||
|
try:
|
||||||
|
self.backend.set_rate(self.settings.get('rate', self.default_system_rate))
|
||||||
|
except OSError:
|
||||||
|
self.settings.pop('rate', None)
|
||||||
try:
|
try:
|
||||||
self.backend.set_audio_device(self.settings.get('sound_output'), self.default_system_audio_device)
|
self.backend.set_audio_device(self.settings.get('sound_output'), self.default_system_audio_device)
|
||||||
except OSError:
|
except OSError:
|
||||||
@ -172,27 +173,29 @@ class Client:
|
|||||||
return Widget(self, backend_settings, parent)
|
return Widget(self, backend_settings, parent)
|
||||||
|
|
||||||
def chunks_from_last_mark(self):
|
def chunks_from_last_mark(self):
|
||||||
for i, chunk in enumerate(self.current_chunks):
|
print(222222222, self.last_mark)
|
||||||
for ci, x in enumerate(chunk):
|
if self.last_mark > -1:
|
||||||
if x == self.last_mark:
|
for i, chunk in enumerate(self.current_chunks):
|
||||||
chunks = self.current_chunks[i:]
|
for ci, x in enumerate(chunk):
|
||||||
chunk = chunk[ci + 1:]
|
if x == self.last_mark:
|
||||||
if chunk:
|
chunks = self.current_chunks[i:]
|
||||||
chunks = (chunk,) + chunks[1:]
|
chunk = chunk[ci + 1:]
|
||||||
else:
|
if chunk:
|
||||||
chunks = chunks[1:]
|
chunks = (chunk,) + chunks[1:]
|
||||||
return chunks
|
else:
|
||||||
|
chunks = chunks[1:]
|
||||||
|
return chunks
|
||||||
return ()
|
return ()
|
||||||
|
|
||||||
def resume_after_configure(self):
|
def resume_after_configure(self):
|
||||||
if not self.synthesizing:
|
if not self.synthesizing:
|
||||||
return
|
return
|
||||||
|
self.current_chunks = self.chunks_from_last_mark()
|
||||||
self.current_chunk_idx = -100
|
self.current_chunk_idx = -100
|
||||||
self.last_mark = -1
|
self.last_mark = -1
|
||||||
self.current_chunks = self.chunks_from_last_mark()
|
|
||||||
self.next_start_is_resume = True
|
self.next_start_is_resume = True
|
||||||
self.synthesizing = bool(self.current_chunks)
|
self.synthesizing = bool(self.current_chunks)
|
||||||
if self.current_chunks:
|
if self.synthesizing:
|
||||||
self.current_chunk_idx = 0
|
self.current_chunk_idx = 0
|
||||||
self.speak_current_chunk()
|
self.speak_current_chunk()
|
||||||
|
|
||||||
@ -207,7 +210,6 @@ class Client:
|
|||||||
if rate != current_rate:
|
if rate != current_rate:
|
||||||
self.settings['rate'] = rate
|
self.settings['rate'] = rate
|
||||||
was_synthesizing = self.synthesizing
|
was_synthesizing = self.synthesizing
|
||||||
self.pause()
|
|
||||||
self.apply_settings()
|
self.apply_settings()
|
||||||
if was_synthesizing:
|
if was_synthesizing:
|
||||||
self.synthesizing = True
|
self.synthesizing = True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user