Skip to content

Commit

Permalink
Add examples
Browse files Browse the repository at this point in the history
  • Loading branch information
microbit-grace committed Mar 20, 2024
1 parent 12a25f1 commit d9b3ffb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions lang/en/typeshed/stdlib/microbit/audio.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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.
"""
Expand All @@ -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.
"""

Expand Down
13 changes: 11 additions & 2 deletions lang/en/typeshed/stdlib/microbit/microphone.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand All @@ -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()``
"""
...

Expand All @@ -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.
Expand Down

0 comments on commit d9b3ffb

Please sign in to comment.