Devlog
Short update feed for projects.
About
This is the Devlog for lavoz where I post short updates on development so you can stay in the loop and we can both avoid twitter.
Lazy config loading: v0.0.17
This patch saw a minor change in the way the configuration is loaded. Previously, if a user did lavoz create-psk -c config.lua then the entire config.lua would get run before any work started getting done. Say there are 300-400 commands. Then, those would get loaded before the mic actually started listening despite the fact that the commands will never be used in the create-psk command!
Now, the only lua that gets run in lavoz create-psk is lavoz.loadModel().
CLI Re-design and simplification: v0.0.16
This patch removed several CLI options such as adding commands and adding model paths through CLI. It also ushers in a re-design of how arguments to flags are presented:
lavoz listen --config=/absolute/path/to/config –> lavoz listen --config any_path
Reasoning
The original CLI design was done when the idea of what lavoz would be was still forming in my head. The work of actually building something often informs you far better about what the best design solutions are, and that was the case here.
The first reason for the change is this: the --argument=value way of doing things removed shell expansion. This constrained the design inside lavoz which previously had to either attempt to expand file-paths or require absolute paths for everything. I chose to require absolute paths. This change ends that: the pattern is --argument value or -a value.
The second reason is that the CLI should essentially mirror the config in many ways. So, you should be able to load the model in the config or add an additional command through CLI without modifying the lua config. The previous design constrained how such an interface could work.
Therefore, out with the old and in with the new!
Note: While the re-design discussed here was implemented, it was also simplified. The work to add certain options that are significantly more complex is going to be deferred until after v0.1.
Simplified installation and a default model: v0.0.15
This patch introduces a new simplified build and install process, thanks to the work I’ve done on restructuring the moonshine-zig bindings. The only dependency needed now is the onnxruntime shared library.
lavoz also now ships Moonshine’s base English model by default, so that it is usable out of the box. The corresponding changes have been made in the default config, as well.
Bug fix in create-psk: v0.0.14
This patch fixes a bug that appeared in testing lavoz create-psk on a debian virtual machine. The transcriber model was loaded after the program prompts users for their passphrase. Then, on slower hardware (or vms), the transcriber won’t be loaded while the user is speaking. Therefore, the passphrase is not recorded and it errors due to a timeout. This is corrected.
Building and installing via zig build install: v0.0.13
This patch introduces a build step zig build install which allows the users to install lavoz and lavozd plus service files for their init system. Current supported init systems are
- systemd (default)
- runit
- openrc
- none (and therefore you will have to create your own service files)
Warning
This feature is somewhat volatile. It only works if the prefix is set to /. There is still work to be done. However, if you follow the README exactly for your set-up, you should encounter no issues.
User Custom Modes: v0.0.12
This patch introduces a long-anticipated (by me) feature: user custom modes!
Brief Overview
This feature is inspired by the vim family of text editors. By modes, it is meant that the behavior of lavoz depends on the mode that the session is in. The user can define different modes in their config.lua and then they can define commands that will only be matched and executed if the command has the proper mode option.
There is a global mode where the session begins by default: lavoz.Mode.global. The global mode is special because any command that is assigned to the global mode can be matched and executed from any other mode. There are also 26 slots available for user custom modes.
Registering User Custom Modes
To create a custom mode users can add something like the following in their config:
custom_mode = lavoz.customMode()
Then, when loading a command they can add as the third argument: mode = custom_mode. Or they can also define multiple modes if they should like: mode = {custom_mode,lavoz.Mode.global}. The default mode for any command is the global mode.
Passphrase creation and verification: v0.0.11
The primary feature of this patch is the first version of the passphrase creation and verification pipeline.
Passphrase creation
To create a passphrase that will allow you to run privileged (root) commands, you need to first run lavoz create-psk --config=[path]. As of v0.0.11, create-psk prompts you for a spoken passphrase and prompts you to repeat it to confirm they match (as is typical). Then, it will ask for the root password using pkexec and install the psk in /etc/lavoz/shadow.
In the future, perhaps it will check if there is already a passphrase installed. If a passphrase is already installed, then it will prompt for the current passphrase and use lavozd to install it with root privileges. Therefore, users will only ever have to physically type in the root password once.
Passphrase verification
Now, the passphrase is verified by lavoz requesting mic access and transcribing the passphrase, then it passes the passphrase to lavozd which normalizes it and verifies it. Then, mic control is returned to the Listener.
Backend-agnostic Transcriber interface: v0.0.10
Transcriber interface
This is the primary new feature of version v0.0.10 and was one of the main blockers for v0.1.0. What’s special about this Transcriber interface is that it is backend-agnostic: meaning that any struct or function which needs a Transcriber can use the same functions to use it without caring what kind of backend is being used. So long as a Backend is available for the type of model that the function is trying to use, then the Transcriber can be used.
The liblavoz Lua API already supports multiple backends, so no additional work needs done for this. The Listener which waits and listens for the user’s commands in listen mode now uses the new Transcriber interface.
Backends
To go along with the Transcriber interface are the available Backends. There are four of them and they correspond to the mtype argument in lavoz.loadmodel() in the liblavoz API:
ParakeetBackendParakeetStreamingBackendMoonshineBackendMoonshineStreamingBackend
Results
Preliminary testing shows that the fastest Backend is currently Moonshine non-streaming. While the extra dependencies which users may not use could be frustrating, this enables far more flexibility. Flexibility has always been one of the primary design principles setting lavoz apart from the competition.
Configuration API liblavoz: v0.0.9
License
Firstly, the license has been updated for this project. It now uses the MPL-2.0 copyleft license.
liblavoz API Changes
The new liblavoz Lua API saw changes to configuration functions.
lavoz.setModelPath(path)has been removed in favor oflavoz.loadModel(mtype,path,opts)lavoz.addCommand()has been renamedlavoz.loadCommand()but the behavior is identical
The arguments to lavoz.loadModel() reflect the near-future intention to rewrite the transcription pipeline to support both parakeet and moonshine backends. Currently, only the moonshine backend is actually implemented and the backend-agnostic Transcriber interface is not yet written. Therefore, attempting to call lavoz.loadModel(lavoz.ModelType.parakeet, path, opts) or similarly lavoz.ModelType.parakeet_streaming or lavoz.ModelType.moonshine (not streaming) will result in a crash at the point of loading the config file. This is acceptable as this software is pre-release.
The next large patch will contain the backend-agnostic Transcriber.
Error Reporting
There has been work done on making the error reporting much more user-friendly for Lua config files. Any errors in users’ config files will cause a crash and an error report in stderr detailing the file, line number, and syntax source of the error.
Program execution API: v0.0.7
This patch brought us significantly closer to an official release v0.1.0.
liblavoz API Changes
The new liblavoz Lua API scopes functions to a global table lavoz, that users can use for customization. Where users would previously use print("Some message"), now they can use either lavoz.print("Some message") or lavoz.printError("Some error"). This will ensure that stdout and stderr can be read/redirected as users might expect.
Where users would previously set the wake word using the global setWakeWord(wake_word), they now must use lavoz.setWakeWord(wake_word). The global addCommand(pattern, fn) has also been replaced with lavoz.addCommand(pattern, fn, opts). The added opts argument is a table which currently has only one possible field requires_root which is a boolean. If the command requires root, then lavoz will prompt the user for their password.
External Program Execution
Whereas previous versions of lavoz could execute user commands, they used os.execute() to do so. In this version, userspace commands can be spawned using the liblavoz API functions lavoz.execProcess(argv) or lavoz.execShell(script). Additionally, the capability to run privileged commands has been added, at last! This is done through the API functions lavoz.privProcess(argv) or lavoz.privShell(script). A command that uses one of these 2 functions must be marked as requires_root.
Disclaimers
The passphrase creation and authentication still rely heavily on typed input with no option to do them through voice. This is a practical matter as implementing it will just take a great deal more work.
There is still not an install step for the program, so lavoz and lavozd are not quite ready to be used.
Introduction of lavozd: v0.0.6
This patch is quite large with a few different changes to make note of.
Dependencies
This project’s forks for dependencies miniaudio and zig-luajit were merged upstream, so the forks have been deleted and the dependencies once again resolved upstream.
Passphrase creation
Some work has been done on the passphrase creation command. For one, the command has been changed from lavoz psk to lavoz create-psk. The latter is more explicit. More importantly, though, is that the functionality of the command has drastically changed. Now, the lavoz create-psk prompts the user for a typed passphrase and from that passphrase it produces a PHC string (what I often call a psk for preshared key or hash). Then, using polkit, this PHC is securely written to a file owned by root and with root-read-only permissions (0400). This shadow file /etc/lavoz/shadow is persistant and is what will be used to verify passphrases that the user uses to attempt to run privileged commands.
The split between getting the user’s passphrase, hashing it, and writing the hash is important because there are constraints on each code path. While the current code prompts the user for a passphrase by the keyboard, that is temporary, and future versions will see spoken passphrases used by transcribing mic input. In order to use pipewire, to get mic input, lavoz create-psk must be run in a user session. However, to write to the shadow file such that it cannot just be read by anyone requires root permissions, and this is the reason for the privilege escalation via polkit password prompt.
lavozd - the miniature daemon
The small daemon lavozd has now been implemented completely in terms of its core functionality. This daemon loads the psk from the shadow file, opens the unix socket, and then waits for a connection. Once a client connects, it challenges it for the passphrase and performs a verification against the loaded psk. Then, if the passphrase passes verification, the daemon spawns a child to execute the root command that was requested of it. The stdout of the child process is streamed back to the client.
The current implementation of the payload for the commands is that they are simply sent as null separated byte strings. There may be a better way of doing this, but this way does work.
Migrated to Zig 0.17.0: v0.0.5
I migrated all of the dependencies to Zig 0.17.0 which involved forking miniaudio and zig-luajit. For now, the forks will be used until the PRs are merged.
There was also reorganization done in the project structure in preparation for the creation of a second binary lavozd which will run as a service daemon and verify passphrases and run root commands when requested by the user through the main binary lavoz. The migration to Zig 0.17.0 was partially to make this easier, because Zig 0.16.0 removed the Unix sockets abstractions. Zig 0.17.0 returned it with improvements. The lavozd code is left unimplemented.
Command parser rewrite v0.0.4
Changes
In this version, I did a complete overhaul of the command parser. There were several issues to address in v0.0.3.
- Numbers were inconsistently transcribed by the machine learning model. Sometimes, they were transcribed as digits (expected) and other times they were transcribed as words (unexpected). The solution was to pass every integer typed argument to a command through a filter that either converts the string to a number or, if that fails, attempts to convert it manually by translating words into integer values in the range
[0, 1,000,000,000,000,000). - Strings worked perfectly if they did not include the terminator words
goorstart. If they did, however, then the state machine would finalize the transcription. The new state machine checks if the terminator is at the end of a completed phrase, which allows the terminators to be used within a string argument to a command.
Commands
I have drafted a few more interesting commands for testing. Primarily, using the Lua library function os.execute(), I added some commands to test:
- opening a program using its name.
"open {app:String}". Tested with firefox. - increasing the volume using wireplumber.
"volume up {x:Num}". Tested successfully. - decreasing the volume using wireplumber.
"volume down {x:Num}". Tested successfully.
Limitations
As previously mentioned, the support for numbers is currently limited. Fractions, decimals, negatives, and perhaps other types of numbers like complex numbers should all ideally have first class support. Otherwise, the command system cannot claim to be infinitely customizable. This is nontrivial to accomplish but it is feasible and will be completed in one of the upcoming versions.
Although the way that the state machine handles the terminators now, works for me and my extensive understanding of the underlying code, it cannot be assumed that any user (especially one of such assistive technology as this) will have the same luck. Minute timing differences between the end of a string typed argument and the terminator word could trigger the state machine to begin execution of a command prematurely cutting off the end of a string, and this outcome would be out of the hands of my code. Therefore, the best solution is to provide an option for users to ‘escape’ the next token using a keyword such as quote or escape. It would be used like so in the following demonstration:
For the command: addCommand("echo {msg:String}", function(msg) print(msg) end)
After the wake-word has been triggered, speaking the words echo I want to quote go go, would produce the output: “I want to go”. This may be more inconvenient for some users, so the current behavior won’t be changed. It should be an option for users that need it, though.
Command system v0.0.3
I introduced a rudimentary command system and tested it with some simple commands. For example, echo a string to print prints “a string to print” to standard out. I also added a command multiply {x:Num} {y:Num} and it works sometimes, but it doesn’t work other times. I am exploring ways of resolving this issue. The key problem is that the transcription model sometimes transcribes numbers as words, not digits. The parser will need to be a little more sophisticated, and perhaps will need to be significantly reworked.
Restructuring v0.0.2
There are a few changes in this version.
DEVLOG removed
The DEVLOG file was removed. This was an attempt to continually track the changes I made and to document my plans for the future, but it was chaotically structured and had grown stale. Instead, I will be tracking changes and documenting future designs here.
SLISP Parser –> Command Parser
Previously, the plan had been to create a very simple LISP-like language called SLISP (Spoken LISP). This language would be the syntax in which commands were spoken and then a SLISP interpreter would then execute the commands. I have determined, however, that creating a new programming language (however simple) is a distraction from the primary goal of making lavoz.
The alternative is to create a syntax for defining commands as a single string. Then, a command parser will be created CmdParser which will take the RawCmd at the head of the CmdQueue do some minimal error checking and then pass arguments to the appropriate lua function.
Removed several command-line arguments
I had originally mapped out several command-line options for different features that are ambitious and remain unstarted. Such features were the ability to save commands as .wav format and a corresponding program argument command lavoz transcribe which would play saved .wav files and allow the user to manually transcribe them. Then using those manual transcriptions there was the lavoz train which I imagined as training the model to improve its accuracy. These features were extra complexity that were left unstarted. Removing them clears away significant complexity, and if I find it feasible to actually implement them then it shouldn’t be too hard to implement them fully at that point.
Runtime structure
This concerns implementation details. Now, there is a Runtime structure that owns the *Lua reference and it also owns the Command list. This runtime is created for non-trivial program paths (not lavoz help or lavoz version) and it lasts the entire program. It is now responsible for loading the config file. It may in the future also keep track of state for lavoz, such as if I add modes to lavoz which I may do!
First entry: State of lavoz
I’ve finally gotten around to publishing a site for my work! This will be a brief introduction to the state of lavoz.
TL;DR: It is not yet production ready.
The current state is that lavoz in listen mode waits for a wake-word and when it hears it transcribes everything and when it hears a terminator word (‘go’/‘start’) it normalizes the transcription and prints it out.
The next step is to write the command parser and the functionality for the commands to execute. Once this is done, the timeline for a 0.1.0 release will be much more clear.