In this lesson, we are building a local, offline voice pipeline using Piper. This engine runs natively on our Jetson Orin Nano hardware, providing fast and natural speech without needing an internet connection. To keep this simple, we will install everything into one specific folder so the software can easily find its own files.
Step 1: System Prep & Piper Installation
Open your terminal and run these commands one by one to create the workspace and download the required files. We are placing everything into the same directory to ensure the AI engine can always find the voice model.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# 1. Update and install dependencies sudo apt update sudo apt install -y wget tar libasound2-dev # 2. Create the main project folder mkdir -p ~/voiceAssistant/piper cd ~/voiceAssistant/piper # 3. Download and extract the Piper binary wget https://github.com/rhasspy/piper/releases/download/2023.11.14-2/piper_linux_aarch64.tar.gz tar -xvzf piper_linux_aarch64.tar.gz # 4. Enter the folder where Piper was extracted cd piper # 5. Download the voice model files into this same folder wget -O en_US-lessac-medium.onnx 'https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/lessac/medium/en_US-lessac-medium.onnx?download=true' wget -O en_US-lessac-medium.onnx.json 'https://huggingface.co/rhasspy/piper-voices/resolve/main/en/en_US/lessac/medium/en_US-lessac-medium.onnx.json?download=true' # 6. Grant execution permissions to the Piper engine chmod +x piper |
Step 2: Identify Your Audio Device
Because every setup is different, we need to tell the system which speaker to use. Run the following command in your terminal:
|
1 |
aplay -l |
Look through the list for your speaker. You will see something like card 0 and device 0. If your card is 0 and device is 0, your identifier is plughw:0,0. You will use these numbers in the Python script below.
Step 3: The Python Pipeline Script
Create a new Python file and paste the code below. Because we installed everything into the same folder, this script will find the files immediately.
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import subprocess # --- CONFIGURATION --- # piperPath: The location of the downloaded Piper executable file. # modelPath: The path to the downloaded AI voice model file (.onnx). # audioDevice: The specific hardware address of the speaker (e.g., plughw:0,0). piperPath = "/home/pjm/voiceAssistant/piper/piper/piper" modelPath = "/home/pjm/voiceAssistant/piper/piper/en_US-lessac-medium.onnx" audioDevice = "plughw:0,0" # --- BUILD THE COMMANDS --- # piperCommand: This runs the AI engine. # --output-raw tells Piper to send out raw audio data instead of a .wav file. piperCommand = piperPath + " --model " + modelPath + " --output-raw" # aplayCommand: This is the Linux sound player that pipes audio to your speakers. # -D: Specifies the device (hardware). # -r 22050: Sets the sample rate. Piper requires 22050Hz for this model. # -f S16_LE: Sets the format to 16-bit Signed Little Endian (the raw digital format). # -t raw: Tells aplay that the incoming data has no header and is pure audio. # -: The hyphen tells aplay to read input from 'stdin' (the data flowing from the pipe). aplayCommand = "aplay -D " + audioDevice + " -r 22050 -f S16_LE -t raw -" # fullCommand: We connect the two commands using a pipe '|'. # This takes the output of the AI (piperCommand) and feeds it directly # into the speaker input (aplayCommand). fullCommand = piperCommand + " | " + aplayCommand # --- RUN THE PIPELINE --- # subprocess.Popen allows us to run the command in the background while # letting our Python code continue to run. speechProcess = subprocess.Popen(fullCommand, shell=True, stdin=subprocess.PIPE) # speechMessage: The text we want the AI to read. # We must encode it as bytes (b"...") to send it to the system. speechMessage = "Hello students. The voice pipeline is verified and operational." speakable=speechMessage.encode('utf-8') # communicate: This sends the text message into the running Piper process. speechProcess.communicate(input=speakable) |
Step 4: Customizing Your Voice
Piper has dozens of voices available. To see the full library, visit the Piper Voices Repository. Download the .onnx and .onnx.json files for your preferred voice, place them in the ~/voiceAssistant/piper/piper/ folder, and update the modelPath variable in your script.
Homework: The Talking Echo Bot
Your assignment is to play around with different voice models, and choose several that you like the best. Then modify the Python script so it becomes an interactive “Echo Bot.” Instead of hardcoding the message, use Python’s input() function to ask the user what to say. When the user types a sentence and presses Enter, your script should pipe that text into Piper and speak it back to you. Use a while True: loop to keep the program running so you can continue talking to your computer. Make a video of your working project, and the voices you chose. In the description in your video, make sure to leave a link back to the video above. That way users can easily click between my video lesson over to your video, and then back to the class video.