@@ -36,12 +36,12 @@ then be played with the ``audio.play()`` function.
3636
3737Audio sampling is the process of converting sound into a digital format.
3838To do this, the microphone takes samples of the sound waves at regular
39- intervals. How many samples are recorded per second is known as the
39+ intervals. The number of samples recorded per second is known as the
4040"sampling rate", so recording at a higher sampling rate increases the sound
41- quality, but as more samples are saved, it also takes more memory.
41+ quality, but as more samples are saved, it also consumes more memory.
4242
4343The microphone sampling rate can be configured during sound recording via
44- the ``rate `` argument in the `` record () `` and `` record_into() `` functions.
44+ the ``AudioFrame. rate() `` method functions.
4545
4646At the other side, the audio playback sampling rate indicates how many samples
4747are played per second. So if audio is played back with a higher sampling rate
@@ -56,24 +56,22 @@ increased or decreased? Let's try it out!::
5656
5757 from microbit import *
5858
59- RECORDING_SAMPLING_RATE = 11000
60-
6159 while True:
6260 if pin_logo.is_touched():
6361 # Record and play back at the same rate
64- my_recording = microphone.record(duration=3000, rate=RECORDING_SAMPLING_RATE )
62+ my_recording = microphone.record(duration=3000)
6563 audio.play(my_recording)
6664
6765 if button_a.is_pressed():
6866 # Play back at half the sampling rate
69- my_recording = microphone.record(duration=3000, rate=RECORDING_SAMPLING_RATE )
70- audio .set_rate(RECORDING_SAMPLING_RATE / 2)
67+ my_recording = microphone.record(duration=3000)
68+ my_recording .set_rate(my_recording.get_rate() / / 2)
7169 audio.play(my_recording)
7270
7371 if button_b.is_pressed():
7472 # Play back at twice the sampling rate
75- my_recording = microphone.record(duration=3000, rate=RECORDING_SAMPLING_RATE )
76- audio .set_rate(RECORDING_SAMPLING_RATE * 2)
73+ my_recording = microphone.record(duration=3000)
74+ my_recording .set_rate(my_recording.get_rate() * 2)
7775 audio.play(my_recording)
7876
7977 sleep(200)
@@ -119,10 +117,10 @@ Functions
119117 * **return **: a representation of the sound pressure level in the range 0 to
120118 255.
121119
122- .. py :function :: record(duration = 3000 , rate = 7812 , wait = True )
120+ .. py :function :: record(duration = 3000 , rate = 7812 )
123121
124- Record sound for the amount of time indicated by `` duration `` at the
125- sampling rate indicated by ``rate ``.
122+ Record sound into an `` AudioFrame `` for the amount of time indicated by
123+ `` duration `` at the sampling rate indicated by ``rate ``.
126124
127125 The amount of memory consumed is directly related to the length of the
128126 recording and the sampling rate. The higher these values, the more memory
@@ -133,10 +131,8 @@ Functions
133131
134132 If there isn't enough memory available a ``MemoryError `` will be raised.
135133
136- :param duration: How much time to record in milliseconds.
134+ :param duration: How long to record in milliseconds.
137135 :param rate: Number of samples to capture per second.
138- :param wait: When set to ``True `` it blocks until the recording is
139- done, if it is set to ``False `` it will run in the background.
140136 :returns: An ``AudioFrame `` with the sound samples.
141137
142138.. py :function :: record_into(buffer, rate = 7812 , wait = True )
@@ -242,11 +238,10 @@ An example of recording and playback with a display animation::
242238 "00000"
243239 )
244240
245- RECORDING_RATE = 5500
246- RECORDING_SECONDS = 5
247- RECORDING_SIZE = RECORDING_RATE * RECORDING_SECONDS
241+ RECORDING_RATE = 3906
242+ RECORDING_MS = 5000
248243
249- my_recording = audio.AudioBuffer(size=RECORDING_SIZE )
244+ my_recording = audio.AudioBuffer(duration=RECORDING_MS, rate=RECORDING_RATE )
250245
251246 while True:
252247 if button_a.is_pressed():
0 commit comments