Allows mapping commands to your voice
Project description
Voice Automatisation
This is a project implementing a speech based command system to automate whatever with python functions. The purpose of this is to have an offline voice assistant (like alexa, siri etc.).
Specifications
This uses a volume threshold for voice activity detection, vosk-based speech recognition and a score based command selection system.
Limitations
Text-To-Speech is not yet supported but will be implemented in the future.
Config
Configuration is done in the config package of voice_automatisation. The config.json must define "input_device_query" and will be populated with "input_device_info" and "vad":
- "input_device_info/rate": what samplerate to use universally for audio data within the package
- "input_device_info/noise_level": this is the peak volume (no unit) of noise that was determined by
config/__init__.py:make_default_config - "input_device_info/speech_level": this is the peak volume (no unit) of speech that was determined by
config/__init__.py:make_default_config - "input_device_info/min_speech_volume_ration": this is used to determine when someone is speaking. the default of 0.2 means that speech is detected at 20% of the normalized
speech_level(seevad/min_speech_volume_ratio) - "vad/noise_level" will be populated by
config/__init__.py:make_default_config - "vad/speech_level" will be populated by
config/__init__.py:make_default_config - "vad/min_speech_volume_ratio" user defined but defaults to 0.2 if left out: the threshold of when audio is classified as speech is set as follows:
threshhold = min_speech_volume_ratio * (speech_level - noise_level)
(Im using slashes to depict membership of the right side to the left)
Usage
The Assistant class defines high level access to the packages functions. It can be given a wake word a list of commands and the path to the vosk model. This Path has to be a raw string literal and must point to a directory containing a directory with the model files. I don't know why.
Example
from voice_automatisation import Assistant
assistant = Assistant(wake_word="test", commands=[], model_path=r"", verbose=True)
assistant.run()
Furthermore the class Assistant provides events that can be overriden when subclassing it. For more information see voice_automatisation/assistant.py:Assistant
How it works
Assistant.run()
Upon calling assistant.run() it will start waiting for the voice activity detection to give it an audio segment, once that happens it gives this segment to the model which returns a transcription. This transcription is then passed to the command-interpreter which returns the associated command or None:
- In the first case the command will be run
- In the second case nothing happens besides calling the fitting event
Executing and defining Commands
voice_automatisation/dataclasses.py defines two structures:
@dataclass
class Keyword:
synonyms: tuple[str]
weight: float
feedback_generator = Generator[Union[str, bool, "feedback_generator"], None, None]
@dataclass
class Command:
identifier: str
keywords: tuple[Keyword]
callback: Callable[[str], feedback_generator]
An example command could look like this:
def callback(transcription: str):
yield "This is how you can have the assistant speak."
yield callback # this recursion can be used for retrying. the generator is stopped after it
# After yielding a callback as in the command definition the assistant will wait on a new input from the
# user and then run the generator from `callback` with the new transctiption
return # to stop the generator and therefore the interaction with the user
command = Command(
identifier="play/pause",
keywords=(Keyword(("play", "pause"), 1), Keyword(("playback",), 3))
callback=callback
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file voice_commands-0.0.1.tar.gz.
File metadata
- Download URL: voice_commands-0.0.1.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd35ca9fbe2d4a794d1cb77e7dd75690151ea65d189d64c9462d980507f3f123
|
|
| MD5 |
b3c83cdc6c70d8bbe16fa64e94e4e75b
|
|
| BLAKE2b-256 |
662bf83529ef6ea41ecd39f640e68285f922663cc7132fa897ddee7b0da9dae1
|
File details
Details for the file voice_commands-0.0.1-py3-none-any.whl.
File metadata
- Download URL: voice_commands-0.0.1-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7759d54a1e58d808d3539302fd2bcf892054b8584116794233652e40ba8f83ca
|
|
| MD5 |
6af917f8afe5f105899ddfe607f8ae5d
|
|
| BLAKE2b-256 |
09df51fead9d54e187a12e19705aacfc08fc8abadd09e9755fadb07236881a84
|