Skip to content

Commit fc85377

Browse files
Microphone stubs
1 parent 6dcc5ab commit fc85377

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
"""Respond to sound using the built-in microphone (V2 only).
22
"""
33

4-
from typing import Optional, Tuple
4+
from typing import Optional, Tuple, Union
55
from ..microbit import SoundEvent
6-
from ..microbit.audio import AudioFrame
6+
from ..microbit.audio import AudioRecording, AudioTrack
77

88
def current_event() -> Optional[SoundEvent]:
99
"""Get the last recorded sound event
@@ -88,12 +88,10 @@ def sound_level_db() -> int:
8888
"""
8989
...
9090

91-
def record(duration: int, rate: int = 7812) -> AudioFrame:
92-
"""Record sound into an ``AudioFrame`` for the amount of time indicated by
91+
def record(duration: int, rate: int = 11_000) -> AudioRecording:
92+
"""Record sound into an ``AudioRecording`` for the amount of time indicated by
9393
``duration`` at the sampling rate indicated by ``rate``.
9494
95-
Example: ``my_frame = microphone.record(3000)``
96-
9795
The amount of memory consumed is directly related to the length of the
9896
recording and the sampling rate. The higher these values, the more memory
9997
it will use.
@@ -105,20 +103,23 @@ def record(duration: int, rate: int = 7812) -> AudioFrame:
105103
106104
:param duration: How long to record in milliseconds.
107105
:param rate: Number of samples to capture per second.
108-
:return: An ``AudioFrame`` with the sound samples.
106+
:returns: An ``AudioRecording`` with the sound samples.
109107
"""
110108
...
111109

112-
def record_into(buffer: AudioFrame, rate: int = 7812, wait: bool = True) -> None:
113-
"""Record sound into an existing ``AudioFrame`` until it is filled,
114-
or the ``stop_recording()`` function is called.
110+
def record_into(buffer: Union[AudioRecording, AudioTrack], wait: bool = True) -> AudioTrack:
111+
"""Record sound into an existing ``AudioRecording`` or ``AudioTrack``
112+
until it is filled, or the ``stop_recording()`` function is called.
115113
116-
Example: ``microphone.record_into(my_frame)``
114+
This function also returns an ``AudioTrack`` created from the provided
115+
input buffer, which length matches the recording duration.
116+
This is useful when recording with ``wait`` set to ``False``, and the
117+
recording is stopped before the input buffer is filled.
117118
118-
:param buffer: An ``AudioFrame`` to record sound.
119-
:param rate: Number of samples to capture per second.
119+
:param buffer: ``AudioRecording`` or ``AudioTrack`` to record sound into.
120120
:param wait: When set to ``True`` it blocks until the recording is
121121
done, if it is set to ``False`` it will run in the background.
122+
:returns: An ``AudioTrack`` which ends where the recording ended.
122123
"""
123124
...
124125

0 commit comments

Comments
 (0)