const int32_t NUMBER_BASE = 10;
const int32_t CHANNEL_COUNT = 2;
const int32_t SAMPLERATE_16000 = 16000;
-const uint32_t AI_VOICE_BUFFER_SIZE = 0x1000; // 2KB buffer for AI voice
-const uint32_t AI_VOICE_QUEUE_SIZE = 20; // 队列大小
+const uint32_t AI_VOICE_BUFFER_SIZE = 0x800; // 2KB buffer for AI voice
+const uint32_t AI_VOICE_QUEUE_SIZE = 10;
// 定义音频数据回调函数类型
* @param size 音频数据大小
* @return 0 成功,-1 失败
*/
-#ifdef BOARD_LEINIAO
-int32_t AI_WriteAudioData(const uint8_t* data, uint32_t size)
-{
- if (data == nullptr || size == 0) {
- MEDIA_ERR_LOG("Invalid audio data parameters");
- return -1;
- }
- AI_WRITE:
- if(g_aiVoiceContext->interruptFlag)
- return -1;
- // 获取全局互斥锁(自动初始化)
- MediaMutexHandle mutex = GetGlobalMutex();
- if (mutex == nullptr) {
- MEDIA_ERR_LOG("Failed to get global mutex");
- return -1;
- }
-
- // 检查AI语音上下文是否存在
- MediaMutexLock(mutex);
- if (g_aiVoiceContext == nullptr) {
- MEDIA_ERR_LOG("AI voice context is null, please start AI voice first");
- MediaMutexUnLock(mutex);
- return -1;
- }
- MediaMutexUnLock(g_aiVoiceContextMutex);
-
- // 写入音频数据到输出流
- int32_t ret = AudioStreamOutStreamWrite(data, size);
- if (ret != 0) {
- // MEDIA_ERR_LOG("Failed to write audio data to output stream, ret=%d", ret);
- // return -1;
- usleep(30*size);
- goto AI_WRITE;
- }
-
- // MEDIA_INFO_LOG("Successfully wrote %u bytes of audio data to output stream", size);
- return 0;
-}
-#else
int32_t AI_WriteAudioData(const uint8_t* data, uint32_t size)
{
if (data == nullptr || size == 0) {
// MEDIA_INFO_LOG("Successfully wrote %u bytes of audio data to output stream", size);
return 0;
}
-#endif
/**
* @brief 检查AI语音服务是否正在运行
* @return true 正在运行,false 未运行