Skip to content

Commit 9299487

Browse files
mjshigginsploeber
authored andcommitted
added ability to select pyaudio device when instantiating a microphone stream
1 parent 712a78b commit 9299487

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

assemblyai/extras.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@ class MicrophoneStream:
2525
def __init__(
2626
self,
2727
sample_rate: int = 44_100,
28+
device_index: int = None
2829
):
2930
"""
3031
Creates a stream of audio from the microphone.
3132
3233
Args:
33-
chunk_size: The size of each chunk of audio to read from the microphone.
34-
channels: The number of channels to record audio from.
3534
sample_rate: The sample rate to record audio at.
35+
device_index: The index of the input device to use. If None, uses the default device.
3636
"""
3737
try:
3838
import pyaudio
@@ -49,6 +49,7 @@ def __init__(
4949
rate=sample_rate,
5050
input=True,
5151
frames_per_buffer=self._chunk_size,
52+
input_device_index=device_index,
5253
)
5354

5455
self._open = True
@@ -143,4 +144,4 @@ def file_from_stream(data: BinaryIO) -> str:
143144
return api.upload_file(
144145
client=Client.get_default().http_client,
145146
audio_file=data,
146-
)
147+
)

0 commit comments

Comments
 (0)