Skip to content

Commit 7299d1f

Browse files
docs: Add audio.sound_level() and tweak audio descriptions.
1 parent 5d4a54c commit 7299d1f

File tree

3 files changed

+28
-6
lines changed

3 files changed

+28
-6
lines changed

docs/audio.rst

+16-4
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,13 @@ Functions
7272
7373
Stops all audio playback.
7474

75+
.. py:function:: sound_level()
76+
77+
Get the sound pressure level produced by audio currently being played.
78+
79+
:return: A representation of the output sound pressure level in the
80+
range 0 to 255.
81+
7582

7683
Built-in sounds **V2**
7784
======================
@@ -251,11 +258,15 @@ AudioFrame
251258
During playback, increasing the sampling rate speeds up the sound
252259
and decreasing it slows it down.
253260

261+
:param sample_rate: The sample rate to set.
262+
254263
.. py:function:: get_rate()
255264
256265
(**V2 only**) Return the configured sampling rate for this
257266
``AudioFrame`` instance.
258267

268+
:return: The configured sample rate.
269+
259270
.. py:function:: copyfrom(other)
260271
261272
Overwrite the data in this ``AudioFrame`` with the data from another
@@ -272,12 +283,13 @@ Technical Details
272283

273284
The ``audio.play()`` function can consume an instance or iterable
274285
(sequence, like list or tuple, or generator) of ``AudioFrame`` instances,
275-
The ``AudioFrame`` default playback rate is 7812 Hz, and the output is a
276-
a PWM signal at 32.5 kHz.
286+
The ``AudioFrame`` default playback rate is 7812 Hz, and can be configured
287+
at any point with the ``AudioFrame.set_rate()`` method.
288+
The ``AudioFrame.set_rate()`` also works while the ``AudioFrame`` is being
289+
played, which will affect the playback speed.
277290

278291
Each ``AudioFrame`` instance is 32 samples by default, but it can be
279-
configured to a different size via constructor and the
280-
``AudioFrame.set_rate()`` method.
292+
configured to a different size via constructor parameters.
281293

282294
So, for example, playing 32 samples at 7812 Hz takes just over 4 milliseconds
283295
(1/7812.5 * 32 = 0.004096 = 4096 microseconds).

docs/microbit_micropython_api.rst

+10
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,16 @@ The Microphone is accessed via the `microphone` object::
108108
set_threshold(128)
109109
# Returns a representation of the sound pressure level in the range 0 to 255.
110110
sound_level()
111+
# Record audio into a new `AudioFrame`
112+
record(duration, rate=7812)
113+
# Record audio into an existing `AudioFrame`
114+
record_into(buffer, rate=7812)
115+
# Returns `True` if the microphone is currently recording audio
116+
is_recording()
117+
# Stop any active audio recording
118+
stop()
119+
# Set the microphone sensitivity (also referred as gain)
120+
set_sensitivity(microphone.SENSITIVITY_MEDIUM)
111121

112122
Pins
113123
----

docs/microphone.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ Functions
139139

140140
:return: A representation of the sound pressure level in the range 0 to 255.
141141

142-
.. py:function:: record(duration=3000, rate=7812)
142+
.. py:function:: record(duration, rate=7812)
143143
144144
Record sound into an ``AudioFrame`` for the amount of time indicated by
145145
``duration`` at the sampling rate indicated by ``rate``.
@@ -174,7 +174,7 @@ Functions
174174

175175
.. py:function:: stop_recording()
176176
177-
Stops an a recording running in the background.
177+
Stops a recording running in the background.
178178

179179
.. py:function:: set_sensitivity(gain)
180180

0 commit comments

Comments
 (0)