void local_voice_task(void *arg) { BOARD_InitDebugConsole(); // PRINTF("1 1 1...\r\n"); // configPRINTF(("1 1 1...\r\n")); int16_t pi16Sample[NUM_SAMPLES_AFE_OUTPUT]; uint32_t len = 0; uint32_t statusFlash = 0; asr_events_t asrEvent = ASR_SESSION_ENDED; struct asr_inference_engine *pInfWW; struct asr_inference_engine *pInfCMD; char **cmdString; // Read Shell Commands Parameters from flash memory. If not available, initialize and write into flash memory. statusFlash = SLN_FLASH_MGMT_Read(ASR_SHELL_COMMANDS_FILE_NAME, (uint8_t *)&appAsrShellCommands, &len); if (statusFlash != SLN_FLASH_MGMT_OK) { configPRINTF(("Failed reading local demo configuration from flash memory.\r\n")); } if (appAsrShellCommands.status != WRITE_SUCCESS) { appAsrShellCommands.demo = ASR_CMD_LED; appAsrShellCommands.followup = ASR_FOLLOWUP_OFF; appAsrShellCommands.multilingual = ASR_ENGLISH; appAsrShellCommands.mute = ASR_MUTE_OFF; appAsrShellCommands.ptt = ASR_PTT_OFF; appAsrShellCommands.timeout = TIMEOUT_TIME_IN_MS; appAsrShellCommands.volume = 55; appAsrShellCommands.status = WRITE_SUCCESS; appAsrShellCommands.asrCfg = ASR_CFG_DEMO_NO_CHANGE; statusFlash = SLN_FLASH_MGMT_Save(ASR_SHELL_COMMANDS_FILE_NAME, (uint8_t *)&appAsrShellCommands, sizeof(app_asr_shell_commands_t)); if ((statusFlash == SLN_FLASH_MGMT_EOVERFLOW) || (statusFlash == SLN_FLASH_MGMT_EOVERFLOW2)) { statusFlash = SLN_FLASH_MGMT_Erase(ASR_SHELL_COMMANDS_FILE_NAME); statusFlash = SLN_FLASH_MGMT_Save(ASR_SHELL_COMMANDS_FILE_NAME, (uint8_t *)&appAsrShellCommands, sizeof(app_asr_shell_commands_t)); if (statusFlash != SLN_FLASH_MGMT_OK) { configPRINTF(("Failed writing local demo configuration in flash memory.\r\n")); } } else if (statusFlash != SLN_FLASH_MGMT_OK) { configPRINTF(("Failed writing local demo configuration in flash memory.\r\n")); } } // PRINTF("2 2 2...\r\n"); // configPRINTF(("2 2 2...\r\n")); initialize_asr(); // We need to reset asrCfg state so we won't remember an unprocessed demo change that was saved in flash appAsrShellCommands.asrCfg = ASR_CFG_DEMO_NO_CHANGE; // PRINTF("3 3 3 ... \r\n"); // configPRINTF(("3 3 3 ... \r\n")); while (!g_xSampleQueue) { vTaskDelay(10); // configPRINTF(("x\r\n")); // PRINTF("x\r\n"); } /* int x = DbgConsole_Printf("4 4 4... \r\n"); configPRINTF(("4 4 4... x = %d\r\n", x)); */ // int x = PRINTF("4 4 4... \r\n"); // configPRINTF(("4 4 4... \r\n")); for (int i = 0; i < 20; i++) { PRINTF("7777777777"); vTaskDelay(100); } // PRINTF("4 4 4... \r\n"); while (1) { if (xQueueReceive(g_xSampleQueue, pi16Sample, portMAX_DELAY) != pdPASS) { configPRINTF(("Could not receive from the queue\r\n")); } // bypass while playing audio clip if (g_bypass_voice_engine > 0) { g_bypass_voice_engine -= NUM_SAMPLES_AFE_OUTPUT; continue; } g_bypass_voice_engine = 0; // push-to-talk if (g_SW1Pressed == true && asrEvent == ASR_SESSION_ENDED && appAsrShellCommands.ptt == ASR_PTT_ON) { g_SW1Pressed = false; g_asrControl.sampleCount = 0; // only English CMD cmdString = get_cmd_string(ASR_ENGLISH, appAsrShellCommands.demo); set_CMD_engine(&g_asrControl, ASR_ENGLISH, appAsrShellCommands.demo, cmdString); oob_demo_control.language = ASR_ENGLISH; asrEvent = ASR_SESSION_STARTED; print_asr_session(asrEvent); // print ASR session status xTaskNotify(appTaskHandle, kWakeWordDetected, eSetBits); } // continue listening to wake words in the selected languages. pInfWW is language specific. if (asrEvent == ASR_SESSION_ENDED && appAsrShellCommands.ptt == ASR_PTT_OFF) { for (pInfWW = g_asrControl.infEngineWW; pInfWW != NULL; pInfWW = pInfWW->next) { if (asr_process_audio_buffer(pInfWW->handler, pi16Sample, NUM_SAMPLES_AFE_OUTPUT, pInfWW->iWhoAmI_inf) == kAsrLocalDetected) { if (asr_get_string_by_id(pInfWW, g_asrControl.result.keywordID[0]) != NULL) { asrEvent = ASR_SESSION_STARTED; /* configPRINTF(("[ASR] Wake Word: %s(%d) - MapID(%d)\r\n", * asr_get_string_by_id(pInfWW, g_asrControl.result.keywordID[0]), * g_asrControl.result.keywordID[0], g_asrControl.result.cmdMapID)); */ if (appAsrShellCommands.cmdresults == ASR_CMD_RES_ON) { configPRINTF((" Trust: %d, SGDiff: %d\r\n", g_asrControl.result.trustScore, g_asrControl.result.SGDiffScore)); } PRINTF("[ASR] Wake Word: %s(%d) \r\n", asr_get_string_by_id(pInfWW, g_asrControl.result.keywordID[0]), g_asrControl.result.keywordID[0]); if (appAsrShellCommands.demo == ASR_CMD_LED) // only English CMD for LED demo, multi-lingual WW is possible. { cmdString = cmd_led_en; set_CMD_engine(&g_asrControl, ASR_ENGLISH, ASR_CMD_LED, cmdString); } else if (appAsrShellCommands.demo & (ASR_CMD_DIALOGIC_1 | ASR_CMD_DIALOGIC_2_TEMPERATURE | ASR_CMD_DIALOGIC_2_TIMER)) // only English CMD for Dialog demo. the current set up // is to starts over from CMD_1 whenever WW is // detected. { cmdString = cmd_dialogic_1_en; set_CMD_engine(&g_asrControl, ASR_ENGLISH, ASR_CMD_DIALOGIC_1, cmdString); } else { cmdString = get_cmd_string(pInfWW->iWhoAmI_lang, appAsrShellCommands.demo); set_CMD_engine(&g_asrControl, pInfWW->iWhoAmI_lang, appAsrShellCommands.demo, cmdString); } oob_demo_control.language = pInfWW->iWhoAmI_lang; reset_WW_engine(&g_asrControl); // Notify App Task Wake Word Detected xTaskNotify(appTaskHandle, kWakeWordDetected, eSetBits); break; // exit for loop } // end of if (asr_get_string_by_id(pInfWW, g_asrControl.keywordID[0]) != NULL) } // end of if (asr_process_audio_buffer(pInfWW->handler, pi16Sample, NUM_SAMPLES_AFE_OUTPUT, // pInfWW->iWhoAmI_inf)) } // end of for (pInfWW = g_asrControl.infEngineWW; pInfWW != NULL; pInfWW = pInfWW->next) } // end of if (asrEvent == ASR_SESSION_ENDED) // now we are getting into command detection. It must detect a command within the waiting time. else if (asrEvent == ASR_SESSION_STARTED) { pInfCMD = g_asrControl.infEngineCMD; if (asr_process_audio_buffer(pInfCMD->handler, pi16Sample, NUM_SAMPLES_AFE_OUTPUT, pInfCMD->iWhoAmI_inf) == kAsrLocalDetected) { if (asr_get_string_by_id(pInfCMD, g_asrControl.result.keywordID[1]) != NULL) { /* configPRINTF(("[ASR] Command: %s(%d) - MapID(%d)\r\n", * asr_get_string_by_id(pInfCMD, g_asrControl.result.keywordID[1]), * g_asrControl.result.keywordID[1], g_asrControl.result.cmdMapID)); * configPRINTF(("%d",pInfCMD->iWhoAmI_lang)); */ configPRINTF(("%d\r\n", vocal2code(pInfCMD->iWhoAmI_lang, g_asrControl.result.keywordID[1]))); configPRINTF(("TEST\r\n")); if (appAsrShellCommands.cmdresults == ASR_CMD_RES_ON) { configPRINTF((" Trust: %d, SGDiff: %d\r\n", g_asrControl.result.trustScore, g_asrControl.result.SGDiffScore)); } /* PRINTF("[ASR] Command: %s(%d) \r\n", * asr_get_string_by_id(pInfCMD, g_asrControl.result.keywordID[1]), * g_asrControl.result.keywordID[1]); // */ PRINTF("%d\r\n", vocal2code(pInfCMD->iWhoAmI_lang, g_asrControl.result.keywordID[1])); PRINTF("TEST\r\n"); g_asrControl.sampleCount = 0; if (appAsrShellCommands.followup) { asrEvent = ASR_SESSION_STARTED; } else { asrEvent = ASR_SESSION_ENDED; } // Notify App Task Command Detected switch (pInfCMD->iWhoAmI_inf) { case ASR_CMD_LED: oob_demo_control.ledCmd = g_asrControl.result.keywordID[1]; xTaskNotify(appTaskHandle, kCommandLED, eSetBits); break; case ASR_CMD_IOT: case ASR_CMD_ELEVATOR: case ASR_CMD_AUDIO: case ASR_CMD_WASH: xTaskNotify(appTaskHandle, kCommandGeneric, eSetBits); break; case ASR_CMD_DIALOGIC_1: if (g_asrControl.result.keywordID[1] >= 0 && g_asrControl.result.keywordID[1] <= 3) // set preheat, set bake, set broil { oob_demo_control.dialogRes = RESPONSE_1_TEMPERATURE; // audio playback. cmdString = cmd_dialogic_2_temperature_en; set_CMD_engine(&g_asrControl, ASR_ENGLISH, ASR_CMD_DIALOGIC_2_TEMPERATURE, cmdString); } else if (g_asrControl.result.keywordID[1] == 4) // set timer { oob_demo_control.dialogRes = RESPONSE_1_TIMER; // audio playback. cmdString = cmd_dialogic_2_timer_en; set_CMD_engine(&g_asrControl, ASR_ENGLISH, ASR_CMD_DIALOGIC_2_TIMER, cmdString); } asrEvent = ASR_SESSION_STARTED; // moving to listen to commands 2 within the same ASR session xTaskNotify(appTaskHandle, kCommandDialog, eSetBits); break; case ASR_CMD_DIALOGIC_2_TEMPERATURE: oob_demo_control.dialogRes = RESPONSE_2_TEMPERATURE; // audio playback. asrEvent = ASR_SESSION_ENDED; // now finishing the ASR session and setting to dialogic cmd 2 xTaskNotify(appTaskHandle, kCommandDialog, eSetBits); break; case ASR_CMD_DIALOGIC_2_TIMER: oob_demo_control.dialogRes = RESPONSE_2_TIMER; // audio playback. asrEvent = ASR_SESSION_ENDED; // now finishing the ASR session and setting to dialogic cmd 2 xTaskNotify(appTaskHandle, kCommandDialog, eSetBits); break; default: xTaskNotify(appTaskHandle, kCommandGeneric, eSetBits); break; } if (asrEvent == ASR_SESSION_ENDED) { print_asr_session(asrEvent); } reset_CMD_engine(&g_asrControl); set_WW_engine(&g_asrControl); } // end of asr_get_string() } // end of asr_process_audio_buffer() // calculate waiting time. g_asrControl.sampleCount += NUM_SAMPLES_AFE_OUTPUT; if (g_asrControl.sampleCount > 16000 / 1000 * appAsrShellCommands.timeout) { g_asrControl.sampleCount = 0; reset_CMD_engine(&g_asrControl); asrEvent = ASR_SESSION_ENDED; print_asr_session(ASR_SESSION_TIMEOUT); // print_asr_session(asrEvent); set_WW_engine(&g_asrControl); // Notify App Task Timeout xTaskNotify(appTaskHandle, kTimeOut, eSetBits); } } // end of else if (asrEvent == ASR_SESSION_STARTED) // reinitialize the ASR engine if language set was changed if (appAsrShellCommands.asrCfg & ASR_CFG_DEMO_LANGUAGE_CHANGED) { initialize_asr(); appAsrShellCommands.asrCfg &= ~ASR_CFG_DEMO_LANGUAGE_CHANGED; } } // end of while }