Skip to content

Instantly share code, notes, and snippets.

@jcsteh
Created August 29, 2023 06:42
Show Gist options
  • Save jcsteh/49a37b4e12297334d5b97d4f8cc6110e to your computer and use it in GitHub Desktop.
Save jcsteh/49a37b4e12297334d5b97d4f8cc6110e to your computer and use it in GitHub Desktop.
An NVDA synth driver which logs time stamped speech output.
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