Skip to content

Commit d9b3ffb

Browse files
Add examples
1 parent 12a25f1 commit d9b3ffb

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lang/en/typeshed/stdlib/microbit/audio.pyi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,9 +173,12 @@ class AudioFrame:
173173
"""Configure the sampling rate associated with the data in the
174174
``AudioFrame`` instance (V2 only).
175175
176+
Example: ``my_frame.set_rate(7812)``
177+
176178
For recording from the microphone, increasing the sampling rate
177179
increases the sound quality, but reduces the length of audio it
178180
can store.
181+
179182
During playback, increasing the sampling rate speeds up the sound
180183
and decreasing it slows it down.
181184
"""
@@ -184,6 +187,8 @@ class AudioFrame:
184187
"""Get the sampling rate associated with the data in the
185188
``AudioFrame`` instance (V2 only).
186189
190+
Example: ``current_rate = my_frame.get_rate()``
191+
187192
:return: The configured sampling rate for this ``AudioFrame`` instance.
188193
"""
189194

lang/en/typeshed/stdlib/microbit/microphone.pyi

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ def record(duration: int = 3000, rate: int = 7812) -> AudioFrame:
7474
"""Record sound into an ``AudioFrame`` for the amount of time indicated by
7575
``duration`` at the sampling rate indicated by ``rate``.
7676
77+
Example: ``my_frame = microphone.record()``
78+
7779
The amount of memory consumed is directly related to the length of the
7880
recording and the sampling rate. The higher these values, the more memory
7981
it will use.
@@ -93,6 +95,8 @@ def record_into(buffer: AudioFrame, rate: int = 7812, wait: bool = True) -> None
9395
"""Record sound into an existing ``AudioFrame`` until it is filled,
9496
or the ``stop_recording()`` function is called.
9597
98+
Example: ``microphone.record_into()``
99+
96100
:param buffer: An ``AudioFrame`` to record sound.
97101
:param rate: Number of samples to capture per second.
98102
: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
103107
def is_recording() -> bool:
104108
"""Checks whether the microphone is currently recording.
105109
106-
:return: ``True`` if the microphone is currently recording sound, or
107-
``False`` otherwise.
110+
Example: ``is_recording = microphone.is_recording()``
111+
112+
:return: ``True`` if the microphone is currently recording sound, otherwise returns ``False``.
108113
"""
109114
...
110115

111116
def stop_recording() -> None:
112117
"""Stops a recording running in the background.
118+
119+
Example: ``microphone.stop_recording()``
113120
"""
114121
...
115122

@@ -126,6 +133,8 @@ SENSITIVITY_HIGH: float;
126133
def set_sensitivity(gain: float) -> None:
127134
"""Configure the microphone sensitivity.
128135
136+
Example: ``microphone.set_sensitivity(microphone.SENSITIVITY_HIGH)``
137+
129138
The default sensitivity is ``microphone.SENSITIVITY_MEDIUM``.
130139
131140
:param gain: The microphone gain. Use ``microphone.SENSITIVITY_LOW``, ``microphone.SENSITIVITY_MEDIUM``, ``microphone.SENSITIVITY_HIGH``, or a value between these levels.

0 commit comments

Comments
 (0)