Skip to content

Commit

Permalink
docs: Update the recording default rate from 11k to 7812.
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-carlos committed Sep 16, 2024
1 parent 4841b60 commit b129d16
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
10 changes: 7 additions & 3 deletions docs/audio.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ a speaker to pin 0 and GND on the edge connector to hear the sounds.
The ``audio`` module can be imported as ``import audio`` or accessed via
the ``microbit`` module as ``microbit.audio``.

There are three different kinds of audio sources that can be played using the
There are five different kinds of audio sources that can be played using the
:py:meth:`audio.play` function:

1. `Built in sounds <#built-in-sounds-v2>`_ (**V2**),
Expand Down Expand Up @@ -268,7 +268,7 @@ AudioRecording
--------------

.. py:class::
AudioRecording(duration, rate=11_000)
AudioRecording(duration, rate=7812)

The ``AudioRecording`` object contains audio data and the sampling rate
associated to it.
Expand Down Expand Up @@ -305,6 +305,10 @@ AudioRecording
Create an `AudioTrack <#audio.AudioTrack>`_ instance from a portion of
the data in this ``AudioRecording`` instance.

Out-of-range values will be truncated to the recording limits.
If ``end_ms`` is lower than ``start_ms``, an empty track will be
created.

:param start_ms: Where to start of the track in milliseconds.
:param end_ms: The end of the track in milliseconds.
If the default value of ``-1`` is provided it will end the track
Expand Down Expand Up @@ -335,7 +339,7 @@ AudioTrack

When the input buffer has an associated rate (e.g. an ``AudioRecording``
or ``AudioTrack``), the rate is copied. If the buffer object does not have
a rate, the default value of 11_000 is used.
a rate, the default value of 7812 is used.

Changes to an ``AudioTrack`` rate won't affect the original source rate,
so multiple instances pointing to the same buffer can have different
Expand Down
2 changes: 1 addition & 1 deletion docs/microbit_micropython_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ The Microphone is accessed via the `microphone` object::
# Returns a representation of the sound pressure level in the range 0 to 255.
sound_level()
# Record audio into a new `AudioRecording`
recording = record(duration, rate=11_000)
recording = record(duration, rate=7812)
# Record audio into an existing `AudioRecording`
record_into(recording, wait=True)
# Returns `True` if the microphone is currently recording audio
Expand Down
15 changes: 8 additions & 7 deletions docs/microphone.rst
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ Functions

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

.. py:function:: record(duration, rate=11000)
.. py:function:: record(duration, rate=7812)
Record sound into an ``AudioRecording`` for the amount of time indicated by
``duration`` at the sampling rate indicated by ``rate``.
Expand Down Expand Up @@ -267,10 +267,8 @@ An example of recording and playback with a display animation::
"00000"
)

RECORDING_RATE = 3906
RECORDING_MS = 5000

my_recording = audio.AudioRecording(duration=RECORDING_MS, rate=RECORDING_RATE)
RECORDING_RATE = 7812 # The default sample rate
my_recording = audio.AudioRecording(duration=5000, rate=RECORDING_RATE)

while True:
if button_a.is_pressed():
Expand All @@ -283,7 +281,10 @@ An example of recording and playback with a display animation::
if button_b.is_pressed():
audio.play(clipped_recording, wait=False)
while audio.is_playing():
x = accelerometer.get_x()
audio.set_rate(scale(x, (-1000, 1000), (2250, 11000)))
clipped_recording.set_rate(scale(
accelerometer.get_x(),
(-1000, 1000),
(RECORDING_RATE // 2, RECORDING_RATE * 2)
))
sleep(50)
sleep(100)

0 comments on commit b129d16

Please sign in to comment.