5.1.5 Text to Speech (TTS)
Last Version: 11/09/2025
Overview
This chapter introduces the basic functionality and usage of Text-to-Speech (TTS) on SpacemiT platforms.
One-Click Deployment (Optional)
A prebuilt installation Deb package is available for quick setup.
- Firmware requirement: Version ≥ 2.2rc2
- Download firmware: https://archive.spacemit.com/image/k1/version/bianbu/
Install Deb Package
sudo apt update
sudo apt install asr-llm-tts
Restart the device after installation to activate the system service. Then check service logs:
journalctl --user -u demo_serve -f
Observe the system log until the following information:
When the log displays 'All models init successfully!'
, it indicates that the TTS service is running.
Run TTS
tts
Press Enter to start using the text-to-speech function.
Manual Setup
If you prefer to run from source, follow these steps:
Clone Repository
git clone https://gitee.com/bianbu/spacemit-demo.git
Install Environment
sudo apt install python3-venv
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements
Search System Playback Devices
Method 1: Using aplay
root@bianbu:~# aplay -l
**** List of PLAYBACK Hardware Devices ****
card 0: sndhdmi [snd-hdmi], device 0: SSPA2-dummy_codec dummy_codec-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
card 1: sndes8326 [snd-es8326], device 0: i2s-dai0-ES8326 HiFi ES8326 HiFi-0 []
Subdevices: 1/1
Subdevice #0: subdevice #0
Identify the playback device index from the output results, and update the code with this index.
Method 2: Using pactl
Tool to Query Default Playback Device
Install tool:
sudo apt install pulseaudio-utils
List playback devices:
root@bianbu:~# pactl list short sinks
64 alsa_output.platform-snd-card_1.stereo-fallback PipeWire s16le 2ch 48000Hz SUSPENDED
66 alsa_output.platform-c0900100.udc.stereo-fallback PipeWire s16le 2ch 48000Hz SUSPENDED
252 alsa_output.platform-snd-card_0.stereo-fallback PipeWire s16le 2ch 48000Hz SUSPENDED
321 alsa_output.usb-C-Media_Electronics_Inc._USB_Audio_Device-00.analog-stereo PipeWire s16le 2ch 48000Hz SUSPENDED
Test audio output for each device to verify which playback devices are working:
# A. Test playback to card_0
pw-play --target alsa_output.platform-snd-card_1.stereo-fallback /usr/share/sounds/alsa/Front_Center.wav
# B. Test playback to card_1
pw-play --target alsa_output.platform-c0900100.udc.stereo-fallback /usr/share/sounds/alsa/Front_Center.wav
# C. Test playback to card_3
pw-play --target alsa_output.platform-snd-card_0.stereo-fallback /usr/share/sounds/alsa/Front_Center.wav
# D. Test playback to card_4 (external USB speaker)
pw-play --target alsa_output.usb-C-Media_Electronics_Inc._USB_Audio_Device-00.analog-stereo /usr/share/sounds/alsa/Front_Center.wav
After confirming which device works, set it as the default playback device:
pactl set-default-sink alsa_output.usb-C-Media_Electronics_Inc._USB_Audio_Device-00.analog-stereo
Method 3: Graphical Interface (recommended with display)
Use the system’s graphical interface to quickly switch the default playback device by selecting it from the list.
Select the desired device directly from the GUI to switch the default playback device.
Run TTS Program
python 07_tts_demo.py
Enter text in the terminal, and the program will convert it to speech and play the result.