Voice over BLE

Description

Bluetooth SDK version 2.6.0 introduces a new software example for Thunderboard Sense (TB Sense) boards, called SoC – Voice over Bluetooth Low Energy (VoBLE). The example can be created directly from Simplicity Studio's Launcher after a Thunderboard Sense is connected to the PC.

The application samples data from the microphone on TB Sense, runs it through a filter and codec, and sends it over the Bluetooth link to a GATT client.

The GATT client application, which can receive the samples from the Thunderboard, is made available as an NCP host code. It can be run on a PC connected to an EFR32 device programmed with NCP - target image. The default location of the VoBLE NCP host app is:

C:\SiliconLabs\SimplicityStudio\vX\developer\sdks\gecko_sdk_suite\<cur_version>\app\bluetooth\examples_ncp_host\voice_over_bluetooth_low_energy_app

How it Works

The block diagram below summarizes the data flow from the microphone into the Bluetooth link.

Block Diagram

The EFR32 on the TB Sense samples the microphone using the ADC with the sampling rate and resolution configured by the GATT client. The sampled data is then run through a digital filter (if the filter usage is enabled) and coded using ADPCM codec before being sent via the Bluetooth link to the GATT client using notifications.

By default, the high pass filter (HPF) is set as the preferred digital filter. To change the filter type, configure it in the Thunderboard Sense software before compiling. The supported filter types are listed in filter_type_t in filter.h.

/** Filter types */
typedef enum {
  LPF,     /**< Low Pass Filter        */
  HPF,     /**< High Pass Filter       */
  BPF,     /**< Band Pass Filter       */
  NOTCH,   /**< Notch Filter           */
  PEQ,     /**< Peaking Band EQ Filter */
  LSH,     /**< Low Shelf Filter       */
  HSH      /**< High Shelf Filter      */
}filter_type_t;

To change the filter and filtering parameters, choose one of the filters listed above and configure the DEFAULT_FILTER -macro.

/** Default filter */
#define DEFAULT_FILTER                       \
  {                                          \
    HPF,  /** Default filter type */         \
    0,    /** Default gain */                \
    100,  /** Default frequency */           \
    8000, /** Default sampling rate */       \
    2,    /** Default bandwidth in octaves*/ \
  }

On the GATT client side, the application starts by sending the configurations to the TB Sense and idles until audio data is received over notifications. Finally, the received data is saved into a file.

Setting up

To test this solution, you need one TB Sense and one WSTK with any of our EFR32BG/MG or BGM radio boards.

Thunderboard Sense (GATT Server)

  1. Attach the Thunderboard Sense to your PC.

  2. Open Simplicity Studio and select your board (Thunderboard Sense).

  3. Click on the SoC – Voice over Bluetooth Low Energy tile in the Software Examples column to create a new project.

  4. Optionally change the filter type as described earlier.

  5. Build and flash the project to the Thunderboard Sense.

WSTK (GATT Client)

  1. Attach the WSTK (with any radio board) to your PC.

  2. Open Simplicity Studio and select your board (WSTK with any radio board).

  3. Click on the NCP target - Empty tile in the Demos column to run the NCP target code on the board.

  4. Open a command prompt and navigate to.

    C:\SiliconLabs\SimplicityStudio\vX\developer\sdks\gecko_sdk_suite\<cur_version>\app\bluetooth\examples_ncp_host\voice_over_bluetooth_low_energy_app\

  5. Run make-command (it is recommended to use mingw32, but cygwin can also work).

    This will create four new folders: build, exe, lst and scripts.

  6. Navigate to the exe-subdirectory. If the compiling was successful, you will see the executable application called voice_over_bluetooth_low_energy_app.exe.

Usage

Running voice_over_bluetooth_low_energy_app.exe, you should be greeted by the following help message.

Help message

The program can be configured using the flags shown in the above image. When giving the parameters to the program, all units must be omitted.

Few notes about the parameters:

Saving the Audio into a File

To record audio into an audio file using this ncp-host-application, you will have to provide at least the following parameters (examples in parenthesis):

In the example below, the verbose mode is used with the default settings for both sampling rate and resolution (16 kHz and 12 bits respectively) and saving the audio data in a file called my_audio_file.

Command output

If you have activated the verbose mode, as in the above image, you will get status messages from the GATT client application. The application will stop printing status messages after is has written all the configurations, which in the above image happens after transfer status has successfully been enabled. When the initialization is done, the GATT client (ncp-host) is ready to receive data from the TB Sense.

To start recording and streaming audio data over the BLE link, press and hold TB Sense BTN0 (left button). After the button is pressed, you should see activity on the terminal window, summarizing the transmission progress. All audio data will be saved to a file defined by the output filename -parameter ( my_audio_file.ima in this example ). If a file with a same name already exists, the audio data is appended to the end of that file.

To end the transmission in progress, send a interrupt signal to the application. On Windows OS, a keyboard interrupt signal can be sent with CTRL+C key combination.

Importing to Audacity

(Conversion with SoX explained in the next chapter)

To listen to the audio, you can use a freeware tool such as Audacity to import and decode the data. In Audacity, select File -> Import -> Raw Data and select the audio file you have created. The select VOX ADPCM encoding and write down the sample rate that you used, either 8000 or 16000 Hz. In this example 16000 Hz was used.

Audacity Raw Conversion

After the file is imported, you can listen to it by pressing the Play button on the top left corner. Then, you can export the file to wav format through File -> Export Audio.

Optionally, you can also upload it to Watson’s Speech to Text to get a speech transcription of the audio recording.

Watson Speech to Text

Using the Provided Scripts

There are few scripts provided to streamline the process, by using a command line audio editing software called SoX. To use the scripts, install the SoX 14.4.1 on your machine (SoX 14.4.2 has issues when capturing standard output, for that reason it is required to use the previous version). Windows scripts can be found from …\scripts\win -directory.

run_voble_app.bat

Executes the voice_over_bluetooth_low_energy_app.exe using the parameters given in the config -file.

config.bat

A helper script that is used to define settings.

@echo off

set AUDIODEV=0

set CURRENT_DIR=%~dp0
set VOBLE_HOME_DIR=%CURRENT_DIR%\..\..\exe

set VOBLE_APP=voice_over_bluetooth_low_energy_app.exe
set VOBLE_APP_PARAM=-p COM8 -b 115200 -o audio_data.ima -t 1

set SOX_APP="C:\Program Files (x86)\sox-14-4-1\sox.exe"

Configuration options:

convert.bat

Searches the exe-folder for all files of a specified format and converts them to wav-format using SoX. Works for .ima or .s16 files.

Usage: convert.bat ima --OR-- convert.bat s16

Source

The source code of this project can be found in the Bluetooth SDK, as explained in the Description section.