你好,我是乐鑫开发的新手。
目前我在基于ESP-SkaiNet的sample,开发语音助手。当提示词唤醒后对用户输入的 语音保存和处理。
我想请教一下,当我通过afe_handle->fetch,res->data获得的音频数据是什么格式?PCM吗?获取的音频数据如何播放出来?
void feed_Task(void *arg)
{
esp_afe_sr_data_t *afe_data = arg;
int audio_chunksize = afe_handle->get_feed_chunksize(afe_data);
int nch = afe_handle->get_channel_num(afe_data);
int feed_channel = esp_get_feed_channel();
assert(nch <= feed_channel);
int16_t *i2s_buff = malloc(audio_chunksize * sizeof(int16_t) * feed_channel);
assert(i2s_buff);
while (task_flag) {
esp_get_feed_data(false, i2s_buff, audio_chunksize * sizeof(int16_t) * feed_channel);
afe_handle->feed(afe_data, i2s_buff);
}
if (i2s_buff) {
free(i2s_buff);
i2s_buff = NULL;
}
vTaskDelete(NULL);
}
int16_t *buff;
int buff_index;
int buff_total;
int afe_chunksize;
void detect_Task(void *arg)
{
esp_afe_sr_data_t *afe_data = arg;
int afe_chunksize = afe_handle->get_fetch_chunksize(afe_data);
char *mn_name = esp_srmodel_filter(models, ESP_MN_PREFIX, ESP_MN_CHINESE);
printf("multinet:%s\n", mn_name);
esp_mn_iface_t *multinet = esp_mn_handle_from_name(mn_name);
model_iface_data_t *model_data = multinet->create(mn_name, 6000);
esp_mn_commands_update_from_sdkconfig(multinet, model_data); // Add speech commands from sdkconfig
int mu_chunksize = multinet->get_samp_chunksize(model_data);
assert(mu_chunksize == afe_chunksize);
//print active speech commands
multinet->print_active_speech_commands(model_data);
printf("------------detect start------------\n");
while (task_flag) {
afe_fetch_result_t* res = afe_handle->fetch(afe_data);
if (!res || res->ret_value == ESP_FAIL) {
printf("fetch error!\n");
break;
}
if (res->wakeup_state == WAKENET_DETECTED) {
printf("WAKEWORD DETECTED\n");
multinet->clean(model_data); // clean all status of multinet
afe_chunksize = afe_handle->get_fetch_chunksize(afe_data);
buff = malloc(1024 * afe_chunksize * sizeof(int16_t));
buff_index = 0;
buff_total = 0;
assert(buff);
} else if (res->wakeup_state == WAKENET_CHANNEL_VERIFIED) {
printf("WAKENET_CHANNEL_VERIFIED\n");
play_voice = -1;
detect_flag = 1;
printf("AFE_FETCH_CHANNEL_VERIFIED, channel index: %d\n", res->trigger_channel_id);
}
if (detect_flag == 1) {
if (res->vad_state == AFE_VAD_SPEECH) {
if (res && res->ret_value != ESP_FAIL) {
memcpy(buff + buff_index, res->data, afe_chunksize * 1 * sizeof(int16_t));
buff_index += afe_chunksize * 1 * sizeof(int16_t);
}
}
esp_mn_state_t mn_state = multinet->detect(model_data, res->data);
if (mn_state == ESP_MN_STATE_DETECTING) {
continue;
}
if (mn_state == ESP_MN_STATE_DETECTED) {
printf("Detected\n");
esp_mn_results_t *mn_result = multinet->get_results(model_data);
for (int i = 0; i < mn_result->num; i++) {
printf("TOP %d, command_id: %d, phrase_id: %d, string:%s prob: %f\n",
i+1, mn_result->command_id, mn_result->phrase_id, mn_result->string, mn_result->prob);
}
printf("\n-----------listening-----------\n");
}
if (mn_state == ESP_MN_STATE_TIMEOUT) {
printf("\n-----------playing user speeking-----------\n");
printf("length %d\n", buff_index);
wake_up_action();
play_audio_voice(buff, buff_index);
esp_mn_results_t *mn_result = multinet->get_results(model_data);
printf("timeout, string:%s\n", mn_result->string);
afe_handle->enable_wakenet(afe_data);
detect_flag = 0;
free(buff);
printf("\n-----------awaits to be waken up-----------\n");
continue;
}
}
}
if (model_data) {
multinet->destroy(model_data);
model_data = NULL;
}
printf("detect exit\n");
vTaskDelete(NULL);
}
afe_handle->fetch获得的音频数据如何播放?
Re: afe_handle->fetch获得的音频数据如何播放?
输出的格式是PCM格式,采样率为16KHz,编码为 int16,如果开发板支持,可以通过esp_audio_play这个函数播放。
Re: afe_handle->fetch获得的音频数据如何播放?
是的,已经调通了,之前播放的采样率设置的不对
Who is online
Users browsing this forum: No registered users and 2 guests