You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
***If you encounter compilation or build errors with the `Record_and_stream` example, please try using the [`arduino-audio-tools` library version __0.9.6__](https://github.com/pschatzmann/arduino-audio-tools/releases/tag/v0.9.6).***
446
+
***__Important:__ This code requires `arduino-audio-tools` version __v0.9.6__ to compile.***
447
447
448
-
Make sure to install these libraries in the Arduino IDE before uploading the code to your Nicla Voice board.
448
+
Make sure that you have updated the NDP120 firmware. See the steps [here](#ndp120-processor-firmware-update).
449
449
450
450
```arduino
451
451
// Include necessary libraries for the Nicla Voice board, audio processing, and G722 codec support
452
452
#include "Arduino.h"
453
453
#include "NDP.h"
454
+
455
+
#undef abs
456
+
#define USE_INT24_FROM_INT
454
457
#include "AudioTools.h"
455
458
#include "AudioCodecs/CodecG722.h"
456
459
457
-
// Create an instance of the G722Encoder class for handling audio encoding
458
460
G722Encoder encoder;
459
461
460
-
// Declare a buffer to temporarily store audio data
461
462
uint8_t data[2048];
462
463
463
-
// Define a function to turn on the green LED for a short duration as an event indicator
464
464
void ledGreenOn() {
465
465
nicla::leds.begin();
466
466
nicla::leds.setColor(green);
@@ -470,49 +470,37 @@ void ledGreenOn() {
470
470
}
471
471
472
472
void setup() {
473
-
// Start UART communication at 115200 baud
474
-
Serial.begin(115200);
475
473
476
-
// Initialize the Nicla Voice board, disable the LDO
474
+
Serial.begin(115200);
477
475
nicla::begin();
478
476
nicla::disableLDO();
479
-
480
-
// Initialize the built-in RGB LED, set up as an event indicator
481
477
nicla::leds.begin();
478
+
482
479
NDP.onEvent(ledGreenOn);
483
480
484
-
// Set up the G722 encoder (1 channel, 16 kHz sample rate)
485
481
AudioBaseInfo bi;
486
482
bi.channels = 1;
487
483
bi.sample_rate = 16000;
484
+
488
485
encoder.setOptions(0);
489
486
encoder.begin(bi);
490
487
491
-
// Set the output stream for the encoder to the serial port
492
488
encoder.setOutputStream(Serial);
493
489
494
-
// Load the required firmware packages for the NDP processor, turn on the onboard microphone
495
490
NDP.begin("mcu_fw_120_v91.synpkg");
496
491
NDP.load("dsp_firmware_v91.synpkg");
497
492
NDP.load("alexa_334_NDP120_B0_v11_v91.synpkg");
498
493
NDP.turnOnMicrophone();
499
-
500
-
// Check the audio chunk size to ensure it doesn't exceed the buffer size
501
494
int chunk_size = NDP.getAudioChunkSize();
502
495
if (chunk_size >= sizeof(data)) {
503
496
for(;;);
504
497
}
505
498
}
506
499
507
-
// Continuously read audio data from the microphone, encode it using the G722 codec, send it to the serial port
508
500
void loop() {
509
-
// Declare a variable to store the length of the extracted audio data
510
501
unsigned int len = 0;
511
502
512
-
// Extract audio data from the NDP and store it in the data buffer
513
503
NDP.extractData(data, &len);
514
-
515
-
// Pass the extracted audio data to the G722 encoder and send it to the serial port
516
504
encoder.write(data, len);
517
505
}
518
506
```
@@ -541,17 +529,54 @@ In the `loop()` function:
541
529
- The length of the extracted audio data is stored in the `len` variable.
542
530
- The extracted audio data is passed to the G722 encoder, which compresses the audio and sends it to the serial port.
543
531
544
-
To extract the audio data on a **Linux computer**, you will need to set up the serial port as raw:
532
+
#### Linux Workflow
533
+
534
+
To extract the audio data on a **Linux computer**, follow the steps below:
535
+
536
+
- Set up the serial port as raw:
545
537
546
538
```bash
547
539
stty -F /dev/ttyACM0 115200 raw
548
540
```
549
-
Dump the data to a file (e.g., test.g722):
541
+
- Dump the data to a file (e.g., test.g722):
550
542
551
543
```bash
552
544
cat /dev/ttyACM0 > test.g722
553
545
```
554
-
Then, you can open the file with a software like [Audacity](https://www.audacityteam.org/) to play back the audio.
546
+
- Install **ffmpeg** with `sudo apt install ffmpeg` to convert the `.g722` file to `.wav`:
547
+
548
+
```bash
549
+
ffmpeg -f g722 -i test.g722 -ar 16000 test.wav
550
+
```
551
+
Then, you can open the `.wav` file with a software like [Audacity](https://www.audacityteam.org/) to play back the audio.
552
+
553
+
#### Windows Workflow
554
+
555
+
To extract the audio data on a **Windows computer**, follow the steps below:
556
+
557
+
Download **PuTTY** for free [here](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html), install it and open it.
558
+
559
+
1. Select "Serial" as connection type
560
+
2. Enter the serial port where your board is connected
561
+
3. Set the baud rate to `115200`
562
+
4. In the left menu, navigate to "Logging"
563
+
5. Select "All session output"
564
+
6. Define the directory to save the recorded file `.g722`
565
+
7. Click on "Open" to start recording audio
566
+
567
+

568
+
569
+
- To stop recording, simply close the terminal window
570
+
- Navigate to your `.g722` file directory, and now it is time to convert it to `.wav`
571
+
- Download **FFmpeg** for Windows [here](https://www.gyan.dev/ffmpeg/builds/)
572
+
- From the Command Prompt (CMD), navigate to the download directory to use it, or add it to your system PATH
573
+
- Run the following command to convert the `.g722` file into `.wav`
0 commit comments