From b129d161192a640b0d034e9071e3b94af6731601 Mon Sep 17 00:00:00 2001 From: Carlos Pereira Atencio Date: Mon, 16 Sep 2024 17:12:09 +0100 Subject: [PATCH] docs: Update the recording default rate from 11k to 7812. --- docs/audio.rst | 10 +++++++--- docs/microbit_micropython_api.rst | 2 +- docs/microphone.rst | 15 ++++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/docs/audio.rst b/docs/audio.rst index 63d93513e..986235f93 100644 --- a/docs/audio.rst +++ b/docs/audio.rst @@ -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**), @@ -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. @@ -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 @@ -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 diff --git a/docs/microbit_micropython_api.rst b/docs/microbit_micropython_api.rst index dece730dc..41cb187de 100644 --- a/docs/microbit_micropython_api.rst +++ b/docs/microbit_micropython_api.rst @@ -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 diff --git a/docs/microphone.rst b/docs/microphone.rst index 0355ffc6a..3818407c1 100644 --- a/docs/microphone.rst +++ b/docs/microphone.rst @@ -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``. @@ -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(): @@ -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)