Audio Service

Last Updated on : 2024-06-04 10:11:49download

This topic describes the commands for the audio service.

Set volume (0x72 87)

The MCU sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x72
Data length 2 0x0003
Data 3
  • Subcommand: 0x87
  • Type (1 byte): 1: System volume. 2: Voice call volume.
  • Volume: 0 to 100. 0 means mute.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

The module returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x72
Data length 2 0x0003
Data 3
  • Subcommand: 0x87
  • Type (1 byte): 1: System volume. 2: Voice call volume.
  • Result:
    • 0: Success.
    • Other values: Failure.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Audio playback from SD card (0x71 27)

An SD card support is required to implement this feature.

The MCU sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x71
Data length 2 0x0004 + N
Data 4 + N
  • Subcommand: 0x27
  • Interface (1 byte): 0: Play on the local speaker. 1: Play on the voice call uplink.
  • Command (1 byte): 0: Stop. 1: Play. 2: Pause. 3: Resume.
  • Audio format:
    • 1: PCM
    • 2: WAVPCM
    • 3: MP3
    • 4: AMR-NB
    • 5: AMR-WB
  • Audio file path (N byte): For example, /sdcard0/ice_8k_16bit.pcm
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

The module returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x71
Data length 2 0x0005
Data 5
  • Subcommand: 0x27
  • Interface (1 byte)
  • Command (1 byte):
  • Audio format
  • Result:
    • 0: Success.
    • Other values: Failure.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Query local audio playback status (0x71 28)

The MCU sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x71
Data length 2 0x0001
Data 1 Subcommand: 0x28
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

The module returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x71
Data length 2 0x0003
Data 3
  • Subcommand: 0x28
  • Status
    • 0: Idle.
    • 1: Playing.
    • 2: Paused.
    • 3: Finished.
  • Result:
    • 0: Success.
    • Other values: Failure.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Report local music playback finished (0x71 2a)

The module reports the completion status when local music playback is finished.

The module sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x71
Data length 2 0x0002
Data 2
  • Subcommand: 0x2A
  • Status: 1, indicating playback is finished.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Set the mute state (0x72 97)

The MCU sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x72
Data length 2 0x0003
Data 3
  • Data[0]: Subcommand 0x97
  • Data[1]: The option.
    • 0: Mute SMS messages.
    • 1: Mute incoming calls.
    • 2: Mute active calls.
  • Data[2]: The set value.
    • 0: Unmute.
    • 1: Mute.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

The module returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x72
Data length 2 0x0003
Data 3
  • Subcommand: 0x97
  • The option:
    • 0: Mute SMS messages.
    • 1: Mute incoming calls.
  • Status:
    • 0x00: Failure.
    • 0x01: Success.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Online TTS service (0x71 45)

  • To enable online TTS, you need to subscribe to Tuya’s online TTS service for your product.
  • The product must get connected to the Tuya platform before it can access the online TTS service.
  • The MCU must send UTF-8 text. Other formats are not supported.
  • This online service uses internet data, and latency may occur if the network is poor.
  • A longer text results in a larger synthesized audio received from the cloud. It is recommended that a single text should not exceed 64 characters.
  • The service operates asynchronously. If the device fails to receive audio data from the cloud within 10 seconds, the request will be terminated.

The MCU sends the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x71
Data length 2 0x0002
Data 2
  • Subcommand: 0x45
  • {“opt”:“play”,
    “timeout”:xxx,
    “context”:“xxx”}
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

opt: indicates the mode. Valid values: play and query.

  • play: The cellular module plays the audio directly after receiving it.

    • timeout: The timeout for receiving the audio from the cloud. The audio playback time is excluded. The timeout defaults to 10s and must be at least 5 seconds.
  • query: Query the current status of TTS playback. When query is selected, context and timeout fields can be left empty.

The module returns the following data.

Field Bytes Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x71
Data length 2 2
Data 2
  • Subcommand: 0x45
  • Data[1]: result
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Result Meaning
-7 The TTS server is not connected.
-6 Incorrect parameter.
-5 Text encoding error.
-4 Network error.
-3 Device is busy.
-2 Failure.
-1 Timeout.
0 Success.
1 TTS service is idle.
2 TTS information is obtained.
3 TTS audio is being requested.
4 TTS audio is downloading.
5 TTS audio is playing.
6 Failed to request TTS audio.
7 Failed to download TTS audio.
8 TTS request timed out.
9 TTS audio finishes playing.

Audio playback from memory (0x71 49)

  • Transfer and control audio data stored in the memory. The module supports up to four audio IDs, with a maximum of 16 KB per audio ID.

  • The audio data is stored in the memory of the module, which gets lost when the device is restarted. Therefore, the MCU should transfer the memory data to the module again.

  • To add audio data, the length of an audio data packet should not exceed 1024 bytes.

The MCU sends the following data.

Field Length (byte) Description
Header 2 0x55aa
Version 1 0x03
Command 1 0x71
Data length 2
  • 00009+N: Add audio data.
  • 0004: Play.
  • 0003: Delete or pause.
  • 0002: Query.
Data Data
  • Subcommand: 0x49
  • Control command (1 byte)
    • 1: Add audio data.
    • 2: Delete an audio ID.
    • 3: Play an audio ID.
    • 4: Pause an audio ID.
    • 5: Query the audio IDs stored in the module’s memory.
  • Audio ID (1 byte): applies to the control commands 1, 2, 3, and 4.
  • Port (1 byte): applies to the control command 3.
    • 0: Play audio on a speaker.
    • 1: Play audio on the voice call’s uplink.
  • Audio file format (1 byte): applies to the control command 1.
    • 1: PCM
    • 2: WAVPCM
    • 3: MP3
    • 4: AMR-NB
    • 5: AMR-WB
  • total_size (2 bytes): applies to the control command 1.
  • offset (2 bytes): applies to the control command 1.
  • Audio data (N bytes): applies to the control command 1.
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Command

Command Combined content
1 Audio ID, audio format, total_size, offset, and audio data
2 Audio ID
3 Audio ID and port
4 Audio ID
5 None

The module returns the following data.

Field Length (byte) Description
Header 2 0x55aa
Version 1 0x00
Command 1 0x71
Data length 2 0x0004/0x0005
Data 4/5
  • Subcommand: 0x49
  • Control command (1 byte)
    • For control commands 1 through 4:
      Status (1 byte): 0 indicates success. Other values indicate failure.
    • For control command 5:
      • The number of audio clips (1 byte)
      • Audio ID (1 byte)
Checksum 1 Start from the header, add up all the bytes, and then divide the sum by 256 to get the remainder.

Status value Meaning
0 Success
1 The upper limit of 16 KB is exceeded.
2 Audio ID is busy.
3 The maximum number of audio IDs is reached.
4 The audio ID does not exist.
5 The data of the audio ID is incomplete.
6 Audio device is busy.
7 Failed to play the audio ID.
8 The size of a single packet exceeds 1024 bytes.

Example

Play the audio ID: 55 AA 03 71 00 04 49 03 01 00 C