Skip to content

Commit 0e9f7e0

Browse files
committed
microphone fixed
1 parent 0398059 commit 0e9f7e0

File tree

1 file changed

+23
-20
lines changed
  • content/hardware/06.nicla/boards/nicla-vision/tutorials/user-manual

1 file changed

+23
-20
lines changed

content/hardware/06.nicla/boards/nicla-vision/tutorials/user-manual/content.md

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ tags:
1111
- RGB
1212
- Sensors
1313
- Machine Learning
14-
author: 'Christopher Mendez'
14+
author: 'Christopher Méndez'
1515
hardware:
1616
- hardware/06.nicla/boards/nicla-vision
1717
software:
@@ -499,7 +499,7 @@ Get or set the pulse width value on a channel. To get, pass no arguments. To set
499499
```python
500500
channel1.pulse_width_percentage(Width) # Width (0-100)
501501
```
502-
As a complete example here is a code to generate a __50% duty cycle__ PWM signal at __1 Mhz__.
502+
As a complete example here is a code to generate a __50% duty cycle__ PWM signal at __10 Khz__.
503503

504504
```python
505505
import time
@@ -509,7 +509,7 @@ from pyb import Pin, Timer
509509

510510
OUT = Pin("D1")
511511

512-
timer1 = Timer(1, freq=1000000)
512+
timer1 = Timer(1, freq=10000)
513513
channel1 = timer1.channel(2, Timer.PWM, pin=OUT, pulse_width_percent=0)
514514

515515
channel1.pulse_width_percent(50)
@@ -730,44 +730,47 @@ The onboard high-performance microphone of the Nicla Vision is the MP34DT06JTR f
730730

731731
The OpenMV IDE includes some examples to get started using the Nicla Vision onboard microphone that can be found on **File > Examples > Audio**. We are going to use the one called `micro_speech.py` to test the machine-learning speech recognition capabilities of the board.
732732

733-
First, download the pre-trained model file from the [example repository](https://raw.githubusercontent.com/iabdalkader/microspeech-yesno-model/main/model.tflite) and copy it to the Nicla Vision storage drive.
733+
First, download the pre-trained model file from the [example repository](https://raw.githubusercontent.com/iabdalkader/microspeech-yesno-model/main/model.tflite) and **copy** it to the Nicla Vision **storage drive**.
734734

735735
![Tflite Machine Learning model in the drive](assets/tflite-model.png)
736736

737737
Reset the board and run the following code on the OpenMV IDE.
738738

739739
```python
740-
import audio
741740
import time
742-
import tf
743-
import micro_speech
741+
from ml.apps import MicroSpeech
744742
import pyb
745743

746-
labels = ["Silence", "Unknown", "Yes", "No"]
747744

748745
led_red = pyb.LED(1)
749746
led_green = pyb.LED(2)
750747

751-
model = tf.load("/model.tflite")
752-
speech = micro_speech.MicroSpeech()
753-
audio.init(channels=1, frequency=16000, gain=24, highpass=0.9883)
754748

755-
# Start audio streaming
756-
audio.start_streaming(speech.audio_callback)
749+
def callback(label, scores):
750+
print(f'\nHeard: "{label}" @{time.ticks_ms()}ms Scores: {scores}')
751+
752+
led = led_green if label == "Yes" else led_red
757753

758-
while True:
759-
# Run micro-speech without a timeout and filter detections by label index.
760-
idx = speech.listen(model, timeout=0, threshold=0.70, filter=[2, 3])
761-
led = led_green if idx == 2 else led_red
762-
print(labels[idx])
763754
for i in range(0, 4):
764755
led.on()
765756
time.sleep_ms(25)
766757
led.off()
767758
time.sleep_ms(25)
768759

769-
# Stop streaming
770-
audio.stop_streaming()
760+
761+
762+
763+
# By default, the MicroSpeech object uses the built-in audio preprocessor (float) and the
764+
# micro speech module for audio preprocessing and speech recognition, respectively. The
765+
# user can override both by passing two models:
766+
# MicroSpeech(preprocessor=ml.Model(...), micro_speech=ml.Model(...), labels=["label",...])
767+
speech = MicroSpeech()
768+
769+
# Starts the audio streaming and processes incoming audio to recognize speech commands.
770+
# If a callback is passed, listen() will loop forever and call the callback when a keyword
771+
# is detected. Alternatively, `listen()` can be called with a timeout (in ms), and it
772+
# returns if the timeout expires before detecting a keyword.
773+
speech.listen(callback=callback, threshold=0.8)
771774
```
772775
After running the code, the matches will be printed on the Serial Monitor if the board hears a `No` or a `Yes`, turning on the red and green LED respectively.
773776

0 commit comments

Comments
 (0)