Prompt tones refer to the device playing local preset audio files or playing specific audio files in certain states based on agreements with the cloud, to meet interaction and information reminder requirements for various scenarios.
Prompt tones are divided into two categories:
The code for local prompt tones is located in the src/wukong/assets/ directory:
assets/
├── scripts/
│ └── gen_media_src.py # MP3 to C file generation script
├── media_src.h # Media resource master header file
├── media_src_zh.h # Chinese prompt tone declarations
├── media_src_zh.c # Chinese prompt tone data
├── media_src_en.h # English prompt tone declarations
├── media_src_en.c # English prompt tone data
└── README.md # This document
The script categorizes MP3 files into two groups, Chinese and English, based on their filename suffixes.
| Suffix | Language | Example |
|---|---|---|
*_zh.mp3 |
Chinese | dingdong_zh.mp3 |
*_en.mp3 |
English | wakeup_en.mp3 |
MP3 files that do not end with the suffixes _zh.mp3 or _en.mp3 will be ignored.
Prepare MP3 files. Place all MP3 files into the same directory. For example, scripts/mp3/ or another MP3 directory in your project.
Run the generation script.
# Run from the assets/scripts directory
cd src/wukong/assets/scripts
python gen_media_src.py <path to mp3 files>
Example: If the MP3 files are in the scripts/mp3 directory:
python gen_media_src.py ./mp3
# Alternatively, use an absolute path
python gen_media_src.py /path/to/your/mp3_folder
Generate the result. The script will perform the following operations:
*.mp3 files in the specified directory.zh/en suffix.assets/ directory:
media_src_zh.h/media_src_zh.c (Chinese)media_src_en.h/media_src_en.c (English)media_src.h (Master header file that includes the above)dingdong_zh.mp3 → C array name: media_src_dingdong_zhwakeup_en.mp3 → C array name:media_src_wakeup_en-) in file names will be replaced with underscores (_).In wukong_audio_player.c, prompt tones are played using wukong_audio_play_data().
#include "media_src.h"
// Play dingdong_zh prompt tone
audio_data = (CONST CHAR_T*)media_src_dingdong_zh;
audio_size = sizeof(media_src_dingdong_zh);
wukong_audio_play_data(AI_AUDIO_CODEC_MP3, audio_data, audio_size);
In the switch (type) block of wukong_audio_player_alert(), select different prompt tones based on the TY_AI_TOY_ALERT_TYPE_E type.
_zh.mp3 or _en.mp3).gen_media_src.py to regenerate the C files.switch (type) block.Example: Add a Chinese prompt tone for network configuration:
case AI_TOY_ALERT_TYPE_NETWORK_CFG:
audio_data = (CONST CHAR_T*)media_src_network_config_zh;
audio_size = sizeof(media_src_network_config_zh);
break;
In addition to local MP3 files, the Wukong AI supports cloud prompt tones: speech generated by cloud TTS (Text-to-Speech) is sent to the device for playback. This allows dynamic changes to the text content and voice timbre without requiring a firmware reflash.
Configure in include/tuya_device_cfg.h:
#define ENABLE_CLOUD_ALERT 1 /* Enable cloud prompt tones. The default value of 0 indicates it is disabled. */
wukong_audio_player_alert(type)
│
├─ ENABLE_CLOUD_ALERT==1 and type supports cloud
│ │
│ └─► wukong_ai_agent_cloud_alert(type)
│ │
│ ├─ Success → Send command to cloud → Cloud TTS stream → Play back in the device
│ └─ Failure → Fallback to local MP3
│
└─ Other cases → Play local media_src_xxx directly
When ENABLE_CLOUD_ALERT == 1, prompt tones of the following types will request the cloud first. If successful, the cloud TTS is played. On failure or if unsupported, it falls back to the local MP3 files.
| Prompt tone type | Description |
|---|---|
AI_TOY_ALERT_TYPE_NETWORK_CONNECTED |
Network connection was successful |
AI_TOY_ALERT_TYPE_WAKEUP |
Wake-up (for example, "Hello, I’m here") |
AI_TOY_ALERT_TYPE_LONG_KEY_TALK |
Press and hold the button to talk |
AI_TOY_ALERT_TYPE_KEY_TALK |
Press the button to talk |
AI_TOY_ALERT_TYPE_WAKEUP_TALK |
Wake up to talk |
AI_TOY_ALERT_TYPE_RANDOM_TALK |
Free talk |
The following types are local only and do not use the cloud (in case the device is offline or the cloud is unsupported):
AI_TOY_ALERT_TYPE_POWER_ON: Power-on announcementAI_TOY_ALERT_TYPE_BATTERY_LOW: Low batteryAI_TOY_ALERT_TYPE_PLEASE_AGAIN: Please repeatAI_TOY_ALERT_TYPE_NOT_ACTIVE: Not pairedAI_TOY_ALERT_TYPE_NETWORK_CFG: Pairing in progressAI_TOY_ALERT_TYPE_NETWORK_FAIL: Network connection failedAI_TOY_ALERT_TYPE_NETWORK_DISCONNECT: Network disconnectedThe application layer can directly call wukong_ai_agent_cloud_alert() to request a cloud prompt tone (requires #include "wukong_ai_agent.h" first).
#include "wukong_ai_agent.h"
/* Request the "Network Connected" cloud prompt tone */
wukong_ai_agent_cloud_alert(AT_NETWORK_CONNECTED);
/* Request the "Wake-up" cloud prompt tone */
wukong_ai_agent_cloud_alert(AT_WAKEUP);
If you have any problems with TuyaOS development, you can post your questions in the Tuya Developer Forum.
Is this page helpful?
YesFeedbackIs this page helpful?
YesFeedback