voca package¶
Subpackages¶
Submodules¶
voca.app module¶
voca.caster_adapter module¶
-
class
voca.caster_adapter.AsyncActionType(*args, **kwargs)[source]¶ Bases:
typing_extensions.Protocol
-
class
voca.caster_adapter.ConditionalAction(condition: types.FunctionType, action: RegisteredAction)[source]¶ Bases:
object
-
class
voca.caster_adapter.FunctionAction(callable: types.FunctionType, positional_arguments: tuple, keyword_arguments: dict)[source]¶ Bases:
object
-
voca.caster_adapter.Key(text)¶
-
class
voca.caster_adapter.Patch(module: types.ModuleType, name: str, new: object)[source]¶ Bases:
object
-
voca.caster_adapter.R¶ alias of
voca.caster_adapter.RegisteredAction
-
class
voca.caster_adapter.RegisteredAction(instruction: AsyncActionType, rdescript: Optional[str] = None)[source]¶ Bases:
object
-
class
voca.caster_adapter.RepeatedAction(action: AsyncActionType, extra: str)[source]¶ Bases:
object
-
voca.caster_adapter.Text(name)¶
voca.cli module¶
Module that contains the command line app.
Why does this file exist, and why not put this in __main__?
You might be tempted to import things from __main__ later, but that will cause problems: the code will get executed twice:
When you run python -mvoca python will execute
__main__.pyas a script. That means there won’t be anyvoca.__main__insys.modules.When you import __main__ it will get executed again (as a module) because there’s no
voca.__main__insys.modules.Also see (1) from http://click.pocoo.org/5/setuptools/#setuptools-integration
voca.config module¶
voca.context module¶
voca.listen module¶
-
class
voca.listen.MyClient(url, mic=1, protocols=None, extensions=None, heartbeat_freq=None, byterate=16000, show_hypotheses=True, save_adaptation_state_filename=None, send_adaptation_state_filename=None, audio_gate=0)[source]¶ Bases:
ws4py.client.threadedclient.WebSocketClient-
closed(code, reason=None)[source]¶ Called when the websocket stream and connection are finally closed. The provided
codeis status set by the other point andreasonis a human readable message.See also
Defined Status Codes http://tools.ietf.org/html/rfc6455#section-7.4.1
-
voca.log module¶
-
voca.log.json_to_file(file: Optional[_io.TextIOWrapper] = None) → Callable[source]¶ Serialize to json and print into a file, defaulting to stdout.
-
voca.log.log_async_call(wrapped_function: Optional[Callable] = None, action_type: Optional[str] = None, include_args: Optional[Iterable[str]] = None, include_result: bool = True) → Callable[source]¶ Decorator/decorator factory that logs inputs and the return result. If used with inputs (i.e. as a decorator factory), it accepts the following parameters: @param action_type: The action type to use. If not given the function name
will be used.
@param include_args: If given, should be a list of strings, the arguments to log. @param include_result: True by default. If False, the return result isn’t logged.
-
voca.log.log_call(wrapped_function: Optional[Callable] = None, action_type: Optional[str] = None, include_args: Optional[Iterable[str]] = None, include_result: bool = True) → Callable[source]¶ Decorator/decorator factory that logs inputs and the return result. If used with inputs (i.e. as a decorator factory), it accepts the following parameters: @param action_type: The action type to use. If not given the function name
will be used.
@param include_args: If given, should be a list of strings, the arguments to log. @param include_result: True by default. If False, the return result isn’t logged.
voca.manager module¶
-
class
voca.manager.Pool(num_workers: int = 1, should_log: bool = True, module_names: List[str] = NOTHING, processes: Set[trio.Process] = NOTHING)[source]¶ Bases:
object
-
voca.manager.async_main(should_log, module_names: Optional[List[str]], num_workers: int)[source]¶ Read newline-separated inputs on stdin, and process them.
-
voca.manager.delegate_task(data: Dict, worker: trio.Process, state: dict, action: eliot.Action)[source]¶ Send input data to worker process over std streams.
-
voca.manager.main(should_log: bool, module_names: Optional[List[str]], num_workers: int)[source]¶ Start the event loop.
-
voca.manager.process_stream(receiver, num_workers: int, should_log: bool, module_names: Optional[List[str]])[source]¶ Handle all the commands coming in by delegating them to workers.
-
voca.manager.replay_child_messages(child: trio.Process) → None[source]¶ Log the child’s messages to the parent’s stdout.
-
voca.manager.run_worker(data: dict, state: dict, pool: Pool)[source]¶ Get a process from the pool, send a job to it. Replace that worker when it quits.
voca.mic module¶
Plot the live microphone signal(s) with matplotlib.
Matplotlib and NumPy have to be installed.
This module is from the sounddevice docs.
voca.parsing module¶
-
class
voca.parsing.Transformer[source]¶ Bases:
lark.visitors.Transformer-
text¶ alias of
builtins.list
-
-
voca.parsing.build_grammar(registry: utils.Registry, rules: List[utils.Rule]) → str[source]¶ Build a lark grammar string by combining rules and definitions in the registry.
-
voca.parsing.build_rules(registry: utils.Registry) → List[utils.Rule][source]¶ Build a list of rules and attach human-readable names.
-
voca.parsing.combine_modules(modules: Iterable[utils.PluginModule]) → utils.WrapperGroup[source]¶ Combine the wrappers of multiple modules into a single WrapperGroup.
-
voca.parsing.combine_registries(registries)[source]¶ Combine several registries together into a single registry.
-
voca.parsing.extract(tree: lark.Tree) → Tuple[str, List][source]¶ Transform the parse tree to extract node type and children.
voca.patching module¶
-
class
voca.patching.PathFinder(modules_to_handle: List[str], fullname_to_vars: Dict[str, Dict[str, Any]])[source]¶ Bases:
object
-
class
voca.patching.PathLoader(namespace: dict, fullname: str, path: Optional[str], target: types.ModuleType)[source]¶ Bases:
object
-
class
voca.patching.Spec(name, loader, submodule_search_locations=NOTHING, has_location=True, cached=False, origin=None)[source]¶ Bases:
object
-
voca.patching.finder_patch(finder: importlib.abc.MetaPathFinder) → Generator[source]¶ Context manager for importing modules with
finderonsys.meta_path.
-
voca.patching.get_package_map(strings: List[str]) → Dict[str, List[str]][source]¶ Return a dict mapping packages to the modules they contain.
-
voca.patching.make_finder(mapping: Dict[str, Dict[str, Any]]) → voca.patching.PathFinder[source]¶ Build a Finder that handles modules in
mapping.
voca.platforms module¶
voca.streaming module¶
-
class
voca.streaming.TerminatedFrameReceiver(stream: trio.abc.ReceiveStream, terminator: bytes, max_frame_length: int = 1048576)[source]¶ Bases:
object- Parse frames out of a Trio stream, where each frame is terminated by a
fixed byte sequence.
For example, you can parse newline-terminated lines by setting the terminator to b”
“.
This uses some tricks to protect against denial of service attacks:
It puts a limit on the maximum frame size, to avoid memory overflow; you
might want to adjust the limit for your situation.
It uses some algorithmic trickiness to avoid “slow loris” attacks. All algorithms are amortized O(n) in the length of the input.
voca.utils module¶
-
class
voca.utils.Handler(registry: voca.utils.Registry, parser: lark.lark.Lark, rule_name_to_function: dict)[source]¶ Bases:
object
-
class
voca.utils.KeyChord(modifiers: List[voca.utils.KeyModifier], name: str)[source]¶ Bases:
object
-
class
voca.utils.PluginModule(wrapper: voca.utils.Wrapper)[source]¶ Bases:
typing_extensions.Protocol
-
class
voca.utils.Registry(pattern_to_function: MutableMapping[str, Callable] = NOTHING, patterns: MutableMapping[KT, VT] = NOTHING)[source]¶ Bases:
object
-
class
voca.utils.Wrapper(registry: voca.utils.Registry, context: voca.utils.Context = <class 'voca.context.AlwaysContext'>)[source]¶ Bases:
object
-
voca.utils.pronunciation_to_value() → MutableMapping[str, Any][source]¶ Return a dict of pronunciation to value.
-
voca.utils.quote(word: str) → str[source]¶ Format a word in single or double quotation marks for lark.
-
voca.utils.run_subprocess(command: List[str], *, input=None, capture_output=False, **options)[source]¶ Run a subprocess an wait for it to exit.
voca.worker module¶
-
voca.worker.async_main(wrapper_group: voca.utils.WrapperGroup)[source]¶ Process input commands as newline-separated json on stdin.
-
voca.worker.collect_modules(import_paths: Iterable[str], use_backup_modules: bool) → List[module][source]¶ Collect modules from import paths, optionally defaulting to backup modules on failure.
-
voca.worker.combine_registries(registries: voca.utils.Registry) → voca.utils.Registry[source]¶ Combine multiple registries into a single one.
-
voca.worker.get_backup_module(import_path: str, backup_dir: pathlib.Path) → module[source]¶ Import a module from the backup directory.
-
voca.worker.get_module(import_path: str, backup_dir: pathlib.Path, use_backup_modules: bool) → module[source]¶ Import module and cache it in backup_dir, returning backup on failure.
-
voca.worker.handle_message(wrapper_group: voca.utils.WrapperGroup, data: dict)[source]¶ Execute the command in
datawith thewrapper_groupcontaining the grammar.
-
voca.worker.load_from_path(import_path: str, filename: str) → module[source]¶ Load a module from a filesystem path.
-
voca.worker.main(import_paths: Tuple[str], use_backup_modules: bool)[source]¶ Get the wrapper group and start the event loop.