Created
August 29, 2023 06:42
-
-
Save jcsteh/49a37b4e12297334d5b97d4f8cc6110e to your computer and use it in GitHub Desktop.
An NVDA synth driver which logs time stamped speech output.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import time | |
from collections import OrderedDict | |
import wx | |
import synthDriverHandler | |
from synthDriverHandler import synthIndexReached, synthDoneSpeaking | |
from speech.commands import IndexCommand | |
import globalVars | |
class SynthDriver(synthDriverHandler.SynthDriver): | |
"""A synth driver which logs time stamped speech output. | |
""" | |
name = "logger" | |
# Translators: Description for a speech synthesizer. | |
description = _("Logger") | |
@classmethod | |
def check(cls): | |
return True | |
supportedSettings = frozenset() | |
_availableVoices = OrderedDict({name: synthDriverHandler.VoiceInfo(name, description)}) | |
def __init__(self): | |
self._log = open( | |
os.path.join(globalVars.appDir, "speech.log"), | |
"wt", | |
encoding="UTF-8" | |
) | |
def terminate(self): | |
self._log.close() | |
def speak(self, speechSequence): | |
textList = [] | |
for item in speechSequence: | |
if isinstance(item, IndexCommand): | |
synthIndexReached.notify(synth=self, index=item.index) | |
elif isinstance(item, str): | |
textList.append(item) | |
t = time.time() | |
text = " ".join(textList) | |
self._log.write(f"{t} {text}\n") | |
synthDoneSpeaking.notify(synth=self) | |
def _get_voice(self): | |
return self.name |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment