8686
8787First, import the module:
8888
89- >>> import sounddevice as sd
89+ .. code :: python
90+
91+ import sounddevice as sd
9092
9193 Playback
9294^^^^^^^^
@@ -95,73 +97,97 @@ Assuming you have a NumPy array named ``myarray`` holding audio data with a
9597sampling frequency of ``fs `` (in the most cases this will be 44100 or 48000
9698frames per second), you can play it back with `sounddevice.play() `:
9799
98- >>> sd.play(myarray, fs)
100+ .. code :: python
101+
102+ sd.play(myarray, fs)
99103
100104 This function returns immediately but continues playing the audio signal in the
101105background. You can stop playback with `sounddevice.stop() `:
102106
103- >>> sd.stop()
107+ .. code :: python
108+
109+ sd.stop()
104110
105111 If you know that you will use the same sampling frequency for a while, you can
106112set it as default using `sounddevice.default.samplerate `:
107113
108- >>> sd.default.samplerate = fs
114+ .. code :: python
115+
116+ sd.default.samplerate = fs
109117
110118 After that, you can drop the *samplerate * argument:
111119
112- >>> sd.play(myarray)
120+ .. code :: python
121+
122+ sd.play(myarray)
113123
114124 Recording
115125^^^^^^^^^
116126
117127To record audio data from your sound device into a NumPy array, use
118128`sounddevice.rec() `:
119129
120- >>> duration = 10 # seconds
121- >>> myrecording = sd.rec(duration * fs, samplerate = fs, channels = 2 )
130+ .. code :: python
131+
132+ duration = 10 # seconds
133+ myrecording = sd.rec(duration * fs, samplerate = fs, channels = 2 )
122134
123135 Again, for repeated use you can set defaults using `sounddevice.default `:
124136
125- >>> sd.default.samplerate = fs
126- >>> sd.default.channels = 2
137+ .. code :: python
138+
139+ sd.default.samplerate = fs
140+ sd.default.channels = 2
127141
128142 After that, you can drop the additional arguments:
129143
130- >>> myrecording = sd.rec(duration * fs)
144+ .. code :: python
145+
146+ myrecording = sd.rec(duration * fs)
131147
132148 This function also returns immediately but continues recording in the
133149background. In the meantime, you can run other commands. If you want to check
134150if the recording is finished, you should use `sounddevice.wait() `:
135151
136- >>> sd.wait()
152+ .. code :: python
153+
154+ sd.wait()
137155
138156 If the recording was already finished, this returns immediately; if not, it
139157waits and returns as soon as the recording is finished.
140158
141159Alternatively, you could have used the *blocking * argument in the first place:
142160
143- >>> myrecording = sd.rec(duration * fs, blocking = True )
161+ .. code :: python
162+
163+ myrecording = sd.rec(duration * fs, blocking = True )
144164
145165 By default, the recorded array has the data type ``'float32' `` (see
146166`sounddevice.default.dtype `), but this can be changed with the *dtype * argument:
147167
148- >>> myrecording = sd.rec(duration * fs, dtype = ' float64' )
168+ .. code :: python
169+
170+ myrecording = sd.rec(duration * fs, dtype = ' float64' )
149171
150172 Simultaneous Playback and Recording
151173^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
152174
153175To play back an array and record at the same time, use `sounddevice.playrec() `:
154176
155- >>> myrecording2 = sd.playrec(myarray, fs, channels = 2 )
177+ .. code :: python
178+
179+ myrecording2 = sd.playrec(myarray, fs, channels = 2 )
156180
157181 The number of output channels is obtained from ``myarray ``, but the number of
158182input channels still has to be specified.
159183
160184Again, default values can be used:
161185
162- >>> sd.default.samplerate = fs
163- >>> sd.default.channels = 2
164- >>> myrecording2 = sd.playrec(myarray)
186+ .. code :: python
187+
188+ sd.default.samplerate = fs
189+ sd.default.channels = 2
190+ myrecording2 = sd.playrec(myarray)
165191
166192 In this case the number of output channels is still taken from ``myarray ``
167193(which may or may not have 2 channels), but the number of input channels is
@@ -180,7 +206,9 @@ to `sounddevice.default.device` or by passing it as *device* argument to
180206Callback Streams
181207^^^^^^^^^^^^^^^^
182208
183- Callback "wire" with `sounddevice.Stream `::
209+ Callback "wire" with `sounddevice.Stream `:
210+
211+ .. code :: python
184212
185213 import sounddevice as sd
186214 duration = 5 # seconds
@@ -193,7 +221,9 @@ Callback "wire" with `sounddevice.Stream`::
193221 with sd.Stream(channels = 2 , callback = callback):
194222 sd.sleep(duration * 1000 )
195223
196- Same thing with `sounddevice.RawStream `::
224+ Same thing with `sounddevice.RawStream `:
225+
226+ .. code :: python
197227
198228 import sounddevice as sd
199229 duration = 5 # seconds
0 commit comments