diff --git a/scripts/examples/10-Arduino-Boards/Nicla-Vision/02-Audio/micro_speech.py b/scripts/examples/10-Arduino-Boards/Nicla-Vision/02-Audio/micro_speech.py new file mode 100644 index 000000000..9495fbe48 --- /dev/null +++ b/scripts/examples/10-Arduino-Boards/Nicla-Vision/02-Audio/micro_speech.py @@ -0,0 +1,29 @@ +# MicroSpeech demo. +# +# Download the pre-trained Yes/No model from here: +# https://raw.githubusercontent.com/iabdalkader/microspeech-yesno-model/main/model.tflite +# Save the model to storage, reset and run the example. +import audio, time, tf, micro_speech, pyb +labels = ['Silence', 'Unknown', 'Yes', 'No'] + +led_red = pyb.LED(1) +led_green = pyb.LED(2) + +model = tf.load('/model.tflite') +speech = micro_speech.MicroSpeech() +audio.init(channels=1, frequency=16000, gain=24, highpass=0.9883) + +# Start audio streaming +audio.start_streaming(speech.audio_callback) + +while (True): + # Run micro-speech without a timeout and filter detections by label index. + idx = speech.listen(model, timeout=0, threshold = 0.78, filter=[2, 3]) + led = led_green if idx == 2 else led_red + print(labels[idx]) + for i in range(0, 4): + led.on(); time.sleep_ms(25) + led.off(); time.sleep_ms(25) + +# Stop streaming +audio.stop_streaming() diff --git a/scripts/examples/10-Arduino-Boards/Portenta-H7/01-Audio/micro_speech.py b/scripts/examples/10-Arduino-Boards/Portenta-H7/01-Audio/micro_speech.py index e71d7185f..9495fbe48 100644 --- a/scripts/examples/10-Arduino-Boards/Portenta-H7/01-Audio/micro_speech.py +++ b/scripts/examples/10-Arduino-Boards/Portenta-H7/01-Audio/micro_speech.py @@ -1,3 +1,8 @@ +# MicroSpeech demo. +# +# Download the pre-trained Yes/No model from here: +# https://raw.githubusercontent.com/iabdalkader/microspeech-yesno-model/main/model.tflite +# Save the model to storage, reset and run the example. import audio, time, tf, micro_speech, pyb labels = ['Silence', 'Unknown', 'Yes', 'No'] diff --git a/src/omv/boards/NICLAV/omv_boardconfig.h b/src/omv/boards/NICLAV/omv_boardconfig.h index 946d505a3..eafc1bb88 100644 --- a/src/omv/boards/NICLAV/omv_boardconfig.h +++ b/src/omv/boards/NICLAV/omv_boardconfig.h @@ -185,7 +185,7 @@ // Domain 2 DMA buffers region. #define OMV_DMA_MEMORY_D2 SRAM2 -#define OMV_DMA_MEMORY_D2_SIZE (6*1024) // Reserved memory for DMA buffers +#define OMV_DMA_MEMORY_D2_SIZE (4*1024) // Reserved memory for DMA buffers #define OMV_DMA_REGION_D2_BASE (OMV_SRAM2_ORIGIN+(0*1024)) #define OMV_DMA_REGION_D2_SIZE MPU_REGION_SIZE_16KB diff --git a/src/omv/ports/stm32/modules/py_audio.c b/src/omv/ports/stm32/modules/py_audio.c index 8bab4bcd9..ca088eb3a 100644 --- a/src/omv/ports/stm32/modules/py_audio.c +++ b/src/omv/ports/stm32/modules/py_audio.c @@ -43,7 +43,7 @@ static DFSDM_Channel_HandleTypeDef hdfsdm; static DFSDM_Filter_HandleTypeDef hdfsdm_filter[AUDIO_MAX_CHANNELS]; static DMA_HandleTypeDef hdma_filter[AUDIO_MAX_CHANNELS]; // NOTE: placed in D2 memory. -#define PDM_BUFFER_SIZE (512) +#define PDM_BUFFER_SIZE (512 * 2) int32_t OMV_ATTR_SECTION(OMV_ATTR_ALIGNED(PDM_BUFFER[PDM_BUFFER_SIZE], 32), ".d2_dma_buffer"); #define SaturaLH(N, L, H) (((N)<(L))?(L):(((N)>(H))?(H):(N))) #else