Build a voice assistant

Note

A minimal example: no GPU, small models, not tuned for quality or latency. For production, work with Meetecho.

This example builds a small assistant you talk to: press Enter, ask a question in English, press Enter again, and it answers with a synthetic voice.

PIPELINE.JSON microphone MicSource between two Enter stt TranscriberSherpa speech to text llm PrompterOllama model on Ollama tts SynthesizerSherpa text to speech speaker SpeakerSink plays the answer console NotifierConsole question and answer PIPELINE.JSON microphone MicSource between two Enter stt TranscriberSherpa speech to text llm PrompterOllama model on Ollama tts SynthesizerSherpa text to speech speaker SpeakerSink plays the answer console

Figure 1. The pipeline of this example: the question goes from the microphone to the speaker, and the console prints both the question and the answer.

  • MicSource records from the microphone, between two presses of Enter;

  • TranscriberSherpa turns the question into text;

  • PrompterOllama asks a language model served by Ollama;

  • SynthesizerSherpa speaks the answer;

  • SpeakerSink plays it;

  • NotifierConsole prints the question and the answer on the terminal.

Everything runs on the CPU, without PyTorch. Once the models are downloaded, nothing leaves the machine: speech recognition, the language model and the voice all run locally.

Limits

The demo shows what the pipeline can do, not how well:

  • it needs a microphone and a speaker on the machine that runs the pipeline: it does not work over SSH or on a server without audio;

  • push-to-talk does not work on Windows, as it waits for Enter with select on the standard input;

  • the transcriber mishears homophones (“too” for “two”, “for” for “four”), and a wrong question gets a wrong answer;

  • a small language model gets facts wrong;

  • the voice skips the words missing from its pronunciation lexicon, which leaves out most names, and the lexicon has no digits, so “100” is not spoken at all: asking the model for numbers in words helps, but does not solve it.

Install

(.venv) $ pip install juturna "juturna-nodes[mic-source,transcriber-sherpa,synthesizer-sherpa,speaker-sink]"

The sherpa nodes bring sherpa-onnx, for speech recognition and synthesis, and the microphone and speaker nodes bring sounddevice. On Linux, sounddevice also needs PortAudio from the system:

$ sudo apt install libportaudio2

The language model is served by Ollama. Install it, then pull the model of the example:

$ ollama pull qwen2.5:1.5b

The Ollama server must be running when the pipeline starts: the desktop app and the Linux service start it; if it is not running, run ollama serve in a terminal of its own. PrompterOllama loads the model on warmup, so without the server the pipeline does not start.

Models

The speech models need no setup: on the first run, TranscriberSherpa and SynthesizerSherpa download them, about 107 MB in all, into ~/.cache/juturna/models/ (or under $XDG_CACHE_HOME). The two models come from Hugging Face at a pinned revision, the lexicon from a sherpa-onnx release; every download is checked against its size and SHA-256, and later runs reuse the files already there.

Model

Used by

Size

License

English streaming zipformer

TranscriberSherpa

73 MB

Apache-2.0

Kitten nano int8

SynthesizerSherpa

28 MB

Apache-2.0

Pronunciation lexicon lexicon-en-us.txt

SynthesizerSherpa

6.3 MB

Not stated upstream, see below

qwen2.5:1.5b

PrompterOllama

986 MB

Apache-2.0

The lexicon needs a word of caution. sherpa-onnx publishes it without a license. Its header lists CMUdict (BSD) and en_list, the English word list of espeak-ng (GPL-3.0), among its sources: the prudent reading is to treat it as GPL-3.0 if you redistribute it. The node downloads it on your machine, and Juturna does not ship it.

To use models you already have, point the model_dir argument of the two sherpa nodes to their folders, and lexicon to the lexicon file.

Write the configuration

Save this as pipeline.json:

{
  "version": "3.0.0",
  "pipeline": {
    "name": "voice_assistant",
    "id": "voice_assistant_01",
    "folder": "./run",
    "nodes": [
      {
        "name": "question",
        "type": "MicSource",
        "configuration": { "push_to_talk": true }
      },
      {
        "name": "stt",
        "type": "TranscriberSherpa",
        "configuration": {}
      },
      {
        "name": "llm",
        "type": "PrompterOllama",
        "configuration": { "model_name": "qwen2.5:1.5b" }
      },
      {
        "name": "tts",
        "type": "SynthesizerSherpa",
        "configuration": {}
      },
      {
        "name": "answer",
        "type": "SpeakerSink",
        "configuration": {}
      },
      {
        "name": "console",
        "type": "NotifierConsole",
        "configuration": {}
      }
    ],
    "links": [
      { "from": "question", "to": "stt" },
      { "from": "stt", "to": "llm" },
      { "from": "stt", "to": "console" },
      { "from": "llm", "to": "tts" },
      { "from": "llm", "to": "console" },
      { "from": "tts", "to": "answer" }
    ]
  }
}

stt and llm both send their messages to console as well: a node can feed any number of others, and each gets the same message without a copy. MicSource and SpeakerSink use the default devices of the system; python -m sounddevice lists the others, to pick with their device argument.

Run it

Run the pipeline in a terminal:

(.venv) $ python -m juturna validate --config pipeline.json
(.venv) $ python -m juturna launch --config pipeline.json --auto \
                                   --timeout 120 --log-level WARNING
[question] press Enter to talk
[question] listening, press Enter to stop
[question] stopped, press Enter to talk
[stt] what is the capital of italy
[llm] The capital of Italy is Rome.

Press Enter, ask your question, press Enter again: the transcribed question and the answer appear on the terminal, and the answer plays on the speaker. Ask as many questions as you like; after --timeout seconds the pipeline stops.

--auto matters: without it, the launcher itself reads Enter to start and stop the pipeline, and the microphone misses the presses meant for it. --log-level WARNING keeps the pipeline logs out of the way.

The microphone only sends audio between the two presses of Enter, so the assistant does not hear itself through the speaker. When you stop talking, it sends a second of silence, and the transcriber closes the sentence at once. You see the final text of each question only, never partial guesses.

PrompterOllama transmits the answer one sentence at a time, while the model writes it, so the voice starts on the first sentence instead of waiting for the whole answer: a long answer comes out as several [llm] lines. A new question interrupts the answer in progress, but the sentences already sent to the voice are still spoken.

PrompterOllama and SynthesizerSherpa add their own time to the timers of each message: set "auto_dump": true on a node to find them in the JSON files of its folder. For the latency of every node, turn on telemetry (Observe a pipeline).

Choose a model

Any model served by Ollama works: pull it and change model_name, nothing else in the pipeline changes. Larger models answer more reliably, and take longer and more memory for each answer. qwen2.5:1.5b is the default of PrompterOllama. For the smallest model of the table below:

$ ollama pull qwen2.5:0.5b
{ "name": "llm", "type": "PrompterOllama",
  "configuration": { "model_name": "qwen2.5:0.5b" } }

PrompterOllama reaches Ollama at endpoint, http://localhost:11434 by default. For a server on another machine, set it to the base address of that server, such as "endpoint": "http://192.168.1.20:11434", without the /api/chat path: the node adds it.

model_name

Download

License

qwen2.5:0.5b

398 MB

Apache-2.0

gemma3:1b

806 MB

Gemma Terms of Use

qwen2.5:1.5b

986 MB

Apache-2.0

llama3.2:3b

2.0 GB

Llama 3.2 Community License

qwen2.5:7b

4.7 GB

Apache-2.0

Sizes and licenses are those listed by the Ollama registry. Check the license of the model you pick before shipping it in a product.

Each question is sent on its own: the assistant keeps no memory of the conversation. The system_prompt argument of PrompterOllama sets how it answers: by default in one or two short sentences, with numbers written as words, because the voice cannot read digits.

The node pages tell the arguments and the message formats of each node: MicSource, TranscriberSherpa, PrompterOllama, SynthesizerSherpa, SpeakerSink.