Revised version updated for Bluetooth SDK 2.9.x, link to the original article
Introduction
The SDK version 2.6.0 introduces a new example for the Thunderboard Sense (TB Sense) called SOC – Voice over Bluetooth Low Energy (VoBLE) which samples data from the analog 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 is also made available as source code. The source code is in the ncp host examples -folder. To build the project into an executable you will also need to use a make-tool, which is part of GNU developer tools. On Windows you need to install the needed tools through Cygwin.
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)
For the TB Sense side, you can simply open the SOC – Voice over Bluetooth Low Energy and flash it as is. By default, the high pass filter (HPF) is set as the preferred filter. If you wish to change the filter type, this must be configured before compiling. The supported filter types are listed in filter_type_t in filter.h.
On the WSTK side you can simply flash the pre-compiled NCP target – Empty example for the specific radio board that you are using to enable communication with the PC.
Next, you will need to compile the ncp application:
Run make-command (can be installed with cyqwin-installer)
$ make
"Building file: …
(Summary of the compiling process)
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
Running this voice_over_bluetooth_low_energy_app.exe you should be greeted by the following help message.
The program can be configured using the flags show 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.
You can find out the address for your device by using the Simplicity Commander as instructed at the beginning of this article.
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.
How to use
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, we are using the verbose mode with the default settings for both sampling rate and resolution (16kHz 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 initialisation 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). Once the button is pressed, you should see activity on the terminal window, summarising the transmission progress. All the 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 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.
Once 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, you need to 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 pervious 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 that is used to output the real time audio stream. Value 0 means that the default system audio 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.
convert.bat
Searches the exe-folder for all the files of specified format and converts them to wav-format using SoX. Works for .ima or .s16 files.
Usage: convert.bat ima --OR-- convert.bat s16
Technical aspect
The block diagram below summarizes the data flow from the analog microphone into the Bluetooth link.
The EFR32 on the TB Sense samples the analog 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.
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.
Bluetooth Knowledge Base
KBA_BT_0902: How to use Voice over Bluetooth Low Energy example for Thunderboard Sense
Introduction
The SDK version 2.6.0 introduces a new example for the Thunderboard Sense (TB Sense) called SOC – Voice over Bluetooth Low Energy (VoBLE) which samples data from the analog 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 is also made available as source code. The source code is in the ncp host examples -folder. To build the project into an executable you will also need to use a make-tool, which is part of GNU developer tools. On Windows you need to install the needed tools through Cygwin.
C:\SiliconLabs\SimplicityStudio\v4\developer\sdks\gecko_sdk_suite\<cur_version>\app\bluetooth\examples_ncp_host\voice_over_bluetooth_low_energy_app
Setup and Configuration
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)
For the TB Sense side, you can simply open the SOC – Voice over Bluetooth Low Energy and flash it as is. By default, the high pass filter (HPF) is set as the preferred filter. If you wish to change the filter type, this must be configured before compiling. The supported filter types are listed in filter_type_t in filter.h.
To change the filter, and filtering parameters, choose one of the filters listed above, and configure the DEFAULT_FILTER -macro.
WSTK (GATT client)
On the WSTK side you can simply flash the pre-compiled NCP target – Empty example for the specific radio board that you are using to enable communication with the PC.
Next, you will need to compile the ncp application:
Running this voice_over_bluetooth_low_energy_app.exe you should be greeted by the following help message.
The program can be configured using the flags show in the above image. When giving the parameters to the program, all units must be omitted.
Few notes about the parameters:
How to use
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, we are using the verbose mode with the default settings for both sampling rate and resolution (16kHz 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 initialisation 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). Once the button is pressed, you should see activity on the terminal window, summarising the transmission progress. All the 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 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.
Once 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, you need to 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 pervious 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.
Configuration options:
convert.bat
Searches the exe-folder for all the files of specified format and converts them to wav-format using SoX. Works for .ima or .s16 files.
Usage: convert.bat ima --OR-- convert.bat s16
Technical aspect
The block diagram below summarizes the data flow from the analog microphone into the Bluetooth link.
The EFR32 on the TB Sense samples the analog 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.
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.