From d9b3ffb02020a4cfe63ee01e5b17154cabc7fef5 Mon Sep 17 00:00:00 2001 From: Grace Date: Wed, 20 Mar 2024 12:33:53 +0000 Subject: [PATCH] Add examples --- lang/en/typeshed/stdlib/microbit/audio.pyi | 5 +++++ lang/en/typeshed/stdlib/microbit/microphone.pyi | 13 +++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/lang/en/typeshed/stdlib/microbit/audio.pyi b/lang/en/typeshed/stdlib/microbit/audio.pyi index fe64689..3ae4510 100644 --- a/lang/en/typeshed/stdlib/microbit/audio.pyi +++ b/lang/en/typeshed/stdlib/microbit/audio.pyi @@ -173,9 +173,12 @@ class AudioFrame: """Configure the sampling rate associated with the data in the ``AudioFrame`` instance (V2 only). + Example: ``my_frame.set_rate(7812)`` + For recording from the microphone, increasing the sampling rate increases the sound quality, but reduces the length of audio it can store. + During playback, increasing the sampling rate speeds up the sound and decreasing it slows it down. """ @@ -184,6 +187,8 @@ class AudioFrame: """Get the sampling rate associated with the data in the ``AudioFrame`` instance (V2 only). + Example: ``current_rate = my_frame.get_rate()`` + :return: The configured sampling rate for this ``AudioFrame`` instance. """ diff --git a/lang/en/typeshed/stdlib/microbit/microphone.pyi b/lang/en/typeshed/stdlib/microbit/microphone.pyi index 19cb2dd..fbd91a0 100644 --- a/lang/en/typeshed/stdlib/microbit/microphone.pyi +++ b/lang/en/typeshed/stdlib/microbit/microphone.pyi @@ -74,6 +74,8 @@ def record(duration: int = 3000, rate: int = 7812) -> AudioFrame: """Record sound into an ``AudioFrame`` for the amount of time indicated by ``duration`` at the sampling rate indicated by ``rate``. + Example: ``my_frame = microphone.record()`` + The amount of memory consumed is directly related to the length of the recording and the sampling rate. The higher these values, the more memory it will use. @@ -93,6 +95,8 @@ def record_into(buffer: AudioFrame, rate: int = 7812, wait: bool = True) -> None """Record sound into an existing ``AudioFrame`` until it is filled, or the ``stop_recording()`` function is called. + Example: ``microphone.record_into()`` + :param buffer: An ``AudioFrame`` to record sound. :param rate: Number of samples to capture per second. :param wait: When set to ``True`` it blocks until the recording is @@ -103,13 +107,16 @@ def record_into(buffer: AudioFrame, rate: int = 7812, wait: bool = True) -> None def is_recording() -> bool: """Checks whether the microphone is currently recording. - :return: ``True`` if the microphone is currently recording sound, or - ``False`` otherwise. + Example: ``is_recording = microphone.is_recording()`` + + :return: ``True`` if the microphone is currently recording sound, otherwise returns ``False``. """ ... def stop_recording() -> None: """Stops a recording running in the background. + + Example: ``microphone.stop_recording()`` """ ... @@ -126,6 +133,8 @@ SENSITIVITY_HIGH: float; def set_sensitivity(gain: float) -> None: """Configure the microphone sensitivity. + Example: ``microphone.set_sensitivity(microphone.SENSITIVITY_HIGH)`` + The default sensitivity is ``microphone.SENSITIVITY_MEDIUM``. :param gain: The microphone gain. Use ``microphone.SENSITIVITY_LOW``, ``microphone.SENSITIVITY_MEDIUM``, ``microphone.SENSITIVITY_HIGH``, or a value between these levels.