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.
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)#
Attach the Thunderboard Sense to your PC.
Open Simplicity Studio and select your board (Thunderboard Sense).
Click on the SoC – Voice over Bluetooth Low Energy tile in the Software Examples column to create a new project.
Optionally change the filter type as described earlier.
Build and flash the project to the Thunderboard Sense.
WSTK (GATT Client)#
Attach the WSTK (with any radio board) to your PC.
Open Simplicity Studio and select your board (WSTK with any radio board).
Click on the NCP target - Empty tile in the Demos column to run the NCP target code on the board.
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\
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.
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.
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:
COM Port: This is the serial port to be used. It should point to the port used by the NCP-target. You can check the correct port number with BGTool or Device Manager, the WSTK lists as a “JLink CDC UART Port”. (If you are having problems identifying the port, you should unplug all WSTKs except the one you wish to use as the NCP.)
Output file name: Filename for the audio data output (without the file extension).
Remote device Bluetooth address: Bluetooth address of the TB Sense board that you are using as GATT client. If left out, the application tries to search devices that match the default UUID of the TB Sense application.
Note: You can find out the address for your device by using the Simplicity Commander. After connecting your debugger, find the Unique ID of the device in the MCU information section. The first 3 bytes and the last 3 bytes of this ID forms the default Bluetooth address of the device.
Enable/Disable filtering: Toggle whether filtering is used, see filter types in previous section for options. The filter is disabled by default.
Enable/Disable encoding: Toggle whether the audio data should be encoded, enabled by default. If encoding is disabled the output filetype will be either “.s8” or “.s16” depending on the sample rate. Encoded filetype is always “.ima” (Dialogic ADPCM -format).
Verbose: If this switch is added the application prints out status messages.
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):
Serial port for the ncp-target ( -p COM6 )
output filename ( -o my_audio_file )
Bluetooth address for the TB Sense ( -a 90:fd:9f:7b:4e:bb )
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.
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.
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.
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:
AUDIODEV
The audio device used to output the real-time audio stream. Value 0 means that the default system output device will be used.
VOBLE_APP_PARAM
Parameters that are passed to the application, see Setup and Configuration.
SOX_APP
Complete path to the SoX application executable.
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.