Skip to content

Prompt_Player


1. Overview

This module is built on top of the audio player and is used to play the prompt sound corresponding to the command word. It encapsulates the process of finding prompt tone information from command words, and provides combined broadcast, selective broadcast, queue broadcast and other functions.


2. Function Description

2.1. Combined broadcast within command words

Since the audio files are large and take up a lot of flash space, in order to save flash space, we can extract the common words in different prompt tones, and then combine the required prompts by multiple audio continuous playback during playback. sound. For example, in the prompt tone of the standard example “Smart Housekeeper” in the SDK, many of the prompt sounds have the same prefix “OK…”, “OK, turn on the air conditioner”, “OK, twenty-five degrees”, ” OK, turn on the lamp.” We can extract the “good” into a single audio file. Then associate the command words in the command word information table through combination. When the user program calls the broadcast, it only needs to pass in the corresponding command word ID or string, and the combination logic has been implemented internally.

Supported interfaces:

  • prompt_play_by_cmd_handle
  • prompt_play_by_cmd_id
  • prompt_play_by_semantic_id
  • prompt_play_by_cmd_string

2.1.1 Example of combined broadcast within command words

  • Suppose the audio content is as follows:

提示音播放器

  • Modify the file [60000]{Smart Butler}V2.xls under the SDK directory (SDK\projects\sample_xxx\firmware\user_file\cmd_info), fill in the audio ID of the combined broadcast, and connect with a plus sign.
  • For example, in the “Broadcast Tone 1 ID” column of the command word “turn on the air conditioner” , fill in 4+5+6

提示音播放器

  • The calling method in the code is as follows, the playing content is “Okay, master, the air conditioner has been turned on for you” , that is, the three audios are combined to broadcast:
//You can use the command word handle to broadcast: the handle is obtained from the recognition result structure
prompt_play_by_cmd_handle(cmd_handle, -1, default_play_done_callback,true);

//Or command word ID broadcast: pass the command word ID of "turn on the air conditioner"
prompt_play_by_cmd_id(2, -1, default_play_done_callback,true);

//Or command word semantic ID mode broadcast: pass the semantic ID of parameter "turn on the air conditioner"
prompt_play_by_semantic_id(0x2BC1943, -1, default_play_done_callback,true);

//Or command word string broadcast: pass the string of parameter "turn on the air conditioner"
prompt_play_by_cmd_string("turn on the air conditioner", -1, default_play_done_callback,true);

2.2. Select broadcast

  • For the diversity of broadcasting, avoid only one prompt tone for each command word, so as to improve the experience of the product. For example, the response to the wake-up word can be “Hello”, or “I am”, or “Please speak” and so on. Whenever the wake-up word spoken by the user is recognized, one of several words can be arbitrarily selected for broadcast.
  • In order to select different prompt tones to broadcast according to different environmental conditions. For example, if the user speaks the command word “increase the volume”, different broadcasts can be selected according to the value of the current volume. The current volume is already at the maximum volume, and the prompt sound can be “OK, the volume has been maximized”, and if the current volume has not reached the maximum, it can broadcast “Okay, the volume has been increased”.

Supported interfaces:

  • prompt_play_by_cmd_handle
  • prompt_play_by_cmd_id
  • prompt_play_by_semantic_id
  • prompt_play_by_cmd_string

2.2.1 Example of selection broadcast

  • Suppose the audio content is as follows:

提示音播放器

  • Modify the file [60000]{Smart Butler}V2.xls under the SDK directory (SDK\projects\sample_xxx\firmware\user_file\cmd_info) , fill in the audio ID of the selected broadcast, and fill in from the broadcast audio 1 ID column, and you can fill in at most 127 columns.

提示音播放器

  • The calling method in the code is as follows, and the second parameter is used to select the broadcast:
    //The second parameter, - 1, means that the broadcast ID is selected by default: "good"
     prompt_play_by_cmd_handle(cmd_handle, -1, default_play_done_callback,true);
     prompt_play_by_cmd_id(2, -1, default_play_done_callback,true);
     prompt_play_by_semantic_id(0x2BC1943, -1, default_play_done_callback,true);
     prompt_play_by_cmd_string("turn on the air conditioner", -1, default_play_done_callback,true);
    
    //The second parameter, - 1, means that the broadcast ID is selected by default: "ok"
     prompt_play_by_cmd_handle(cmd_handle, 0, default_play_done_callback,true);
     prompt_play_by_cmd_id(2, 0, default_play_done_callback,true);
     prompt_play_by_semantic_id(0x2BC1943, 0, default_play_done_callback,true);
     prompt_play_by_cmd_string("turn on the air conditioner", 0, default_play_done_callback,true);
    
    //The second parameter 1 indicates the selection of broadcast 2ID: "master"
     prompt_play_by_cmd_handle(cmd_handle, 1, default_play_done_callback,true);
     prompt_play_by_cmd_id(2, 1, default_play_done_callback,true);
     prompt_play_by_semantic_id(0x2BC1943, 1, default_play_done_callback,true);
     prompt_play_by_cmd_string("turn on the air conditioner", 1, default_play_done_callback,true);
    
    //The second parameter 2 indicates the selection of broadcast 3ID: the broadcast content "has turned on the air conditioner for you"
     prompt_play_by_cmd_handle(cmd_handle, 2, default_play_done_callback,true);
     prompt_play_by_cmd_id(2, 2, default_play_done_callback,true);
     prompt_play_by_semantic_id(0x2BC1943, 2, default_play_done_callback,true);
     prompt_play_by_cmd_string("turn on the air conditioner", 2, default_play_done_callback,true);
    

2.3. Multi-command word combination broadcast

The above explained “combined broadcasting within command words” and “selective broadcasting”. Using the two together can realize combination first and then selection, that is, it can realize broadcasting in different combination modes. Some applications may also require more complex combination functions, combining different options, simply speaking, select first and then combine. This module provides the function of combining the prompt sounds of multiple command words to broadcast together, so that the function of combining first, then selecting, and then combining can be realized.

Supported interfaces:

  • prompt_play_by_multi_cmd_id

2.3.1 Example of multi-command word combination broadcas

  • Suppose the audio content is as follows:

提示音播放器

  • The requirement assumptions are the command words “full light”, “inner light on”, “outer light on”.

  • Modify the file [60000]{Smart Butler}V2.xls under the SDK directory (SDK\projects\sample_xxx\firmware\user_file\cmd_info) , fill in the audio ID of the broadcast

提示音播放器

The calling method in the code is as follows:

prompt_play_info_t p_play_info_all[9] =
{
    //Interior lamp
    {66, -1},    //Turn on the master bedroom light      
    {70, -1},    //Turn on the room light
    {72, -1},    //Turn on the dining room light
    {74, -1},    //Turn on the toilet light

    //Exterior lamp
    {76, -1},    //Turn on the garden light
    {78, -1},    //Turn on the sun lamp

    {62, -1},    //All lights on
    {64, -1},    //Exterior lights on
    {65, -1},    //Interior lamp on
};

void deal_asr_msg_by_multi_cmd_id()
{
    //All lights on: the second parameter indicates the audio playback of 7 command words
    prompt_play_by_multi_cmd_id(p_play_info_all, 7, default_play_done_callback);
    //Full light on: Only the audio of a single light on is played.
    prompt_play_by_multi_cmd_id(&p_play_info_all[6], 1, default_play_done_callback);

    //Interior light on: the second parameter indicates the audio playback of the combination of four command words
    prompt_play_by_multi_cmd_id(p_play_info_all, 4, default_play_done_callback);
    //Interior lamp on: only the audio of a single interior lamp on is played.
    prompt_play_by_multi_cmd_id(&p_play_info_all[8], 4, default_play_done_callback);

    //The exterior lamp is on: the second parameter indicates the audio playback of the combination of three command words
    prompt_play_by_multi_cmd_id(&p_play_info_all[4], 3, default_play_done_callback);
    //Exterior lamp on: only the audio of a single exterior lamp on is played.
    prompt_play_by_multi_cmd_id(&p_play_info_all[7], 1, default_play_done_callback);
}

2.4. Preempt broadcast

Interrupt the prompt tone that is playing, clear the previous broadcast queue, and start a new prompt tone broadcast immediately.

Supported interfaces:

  • prompt_play_by_cmd_handle
  • prompt_play_by_cmd_id
  • prompt_play_by_semantic_id
  • prompt_play_by_cmd_string

The calling method in the code is as follows, the fourth parameter true is used to preempt the broadcast:

 //The fourth parameter, true, interrupts the prompt tone being played, clears the previous broadcast queue, and immediately starts a new prompt tone broadcast.
 prompt_play_by_cmd_handle(cmd_handle, 0, default_play_done_callback,true);
 prompt_play_by_cmd_id(2, 0, default_play_done_callback,true);
 prompt_play_by_semantic_id(0x2BC1943, 0, default_play_done_callback,true);
 prompt_play_by_cmd_string("turn on the air conditioner", 0, default_play_done_callback,true);

2.5. Queue broadcast

Contrary to the preemptive broadcast, it just puts the new prompt tone at the end of the broadcast queue and waits for the player to broadcast in turn. Note that the number of broadcast queues in the SDK is limited. When multiple audio queues are required to broadcast continuously, it is recommended to combine the two methods of combined broadcast + queue broadcast.

Supported interfaces:

  • prompt_play_by_cmd_handle
  • prompt_play_by_cmd_id
  • prompt_play_by_semantic_id
  • prompt_play_by_cmd_string

The calling method in the code is as follows, the fourth parameter false is used for queue broadcasting:

 //The fourth parameter, false, simply places the new prompt tone at the end of the broadcast queue and waits for the player to broadcast in turn.
 prompt_play_by_cmd_handle(cmd_handle, 0, default_play_done_callback,false);
 prompt_play_by_cmd_id(2, 0, default_play_done_callback,false);
 prompt_play_by_semantic_id(0x2BC1943, 0, default_play_done_callback,false);
 prompt_play_by_cmd_string("turn on the air conditioner", 0, default_play_done_callback,false);

2.6. Callback function

All playback interfaces of prompt_player are non-blocking, and will not wait until the end of the prompt sound before returning. But a lot of logic in the application may need to know when the playback ends.

Therefore, all playback interfaces provide callback functions. When calling the broadcast interface, pass in a callback function pointer. When the player finishes playing, it will call the passed in callback function to let the caller handle the relevant logic after the end.

Supported interfaces:

  • prompt_play_by_cmd_handle
  • prompt_play_by_cmd_id
  • prompt_play_by_semantic_id
  • prompt_play_by_cmd_string
  • prompt_play_by_multi_cmd_id

The calling method in the code is as follows: the third parameter is default_ play_ done_ Callback is used to specify the callback function after playback:

 //The third parameter is default_ play_ done_ Callback, the callback function of the playback interface
 prompt_play_by_cmd_handle(cmd_handle, 0, default_play_done_callback,true);
 prompt_play_by_cmd_id(2, 0, default_play_done_callback,true);
 prompt_play_by_semantic_id(0x2BC1943, 0, default_play_done_callback,true);
 prompt_play_by_cmd_string("turn on the air conditioner", 0, default_play_done_callback,true);

 //Playback interface callback function
 void default_play_done_callback(cmd_handle_t cmd_handle)
 {
    resume_voice_in();

    //Add processing logic after playback
 }

2.7. Broadcast status

State query and control of broadcaster, enabling control.

Related interfaces:

  • prompt_player_enable
  • prompt_is_playing
  • prompt_stop_play

he calling method in the code is as follows:

 //Turn on voice broadcast
 prompt_player_enable(ENABLE);

 //Turn off voice broadcast
 prompt_player_enable(DISABLE);

 //Check prompt tone playing status
 if(prompt_is_playing() == true)
 {
      //Playing
 }
 else
 {
      //Playback complete
 }

 //Stop prompt tone playing
 prompt_stop_play();