Skip to content

Select audio input device when streaming from microphone #82

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions assemblyai/extras.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import time
from typing import BinaryIO, Generator
from typing import BinaryIO, Generator, Optional
from warnings import warn

from . import api
Expand All @@ -22,17 +22,13 @@ def __init__(


class MicrophoneStream:
def __init__(
self,
sample_rate: int = 44_100,
):
def __init__(self, sample_rate: int = 44_100, device_index: Optional[int] = None):
"""
Creates a stream of audio from the microphone.

Args:
chunk_size: The size of each chunk of audio to read from the microphone.
channels: The number of channels to record audio from.
sample_rate: The sample rate to record audio at.
device_index: The index of the input device to use. If None, uses the default device.
"""
try:
import pyaudio
Expand All @@ -49,6 +45,7 @@ def __init__(
rate=sample_rate,
input=True,
frames_per_buffer=self._chunk_size,
input_device_index=device_index,
)

self._open = True
Expand Down
Loading