From 8f8509d497404b28d3ef510941f60e5874c6827e Mon Sep 17 00:00:00 2001 From: Mac Date: Fri, 16 Aug 2024 12:38:00 -0400 Subject: [PATCH 1/3] added ability to select pyaudio device when instantiating a microphone stream --- assemblyai/extras.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/assemblyai/extras.py b/assemblyai/extras.py index 7e844b3..1ff6761 100644 --- a/assemblyai/extras.py +++ b/assemblyai/extras.py @@ -25,14 +25,14 @@ class MicrophoneStream: def __init__( self, sample_rate: int = 44_100, + device_index: 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 @@ -49,6 +49,7 @@ def __init__( rate=sample_rate, input=True, frames_per_buffer=self._chunk_size, + input_device_index=device_index, ) self._open = True @@ -143,4 +144,4 @@ def file_from_stream(data: BinaryIO) -> str: return api.upload_file( client=Client.get_default().http_client, audio_file=data, - ) + ) \ No newline at end of file From 86561297f127622961311c14191d7efd531cde24 Mon Sep 17 00:00:00 2001 From: Patrick Loeber <98830383+ploeber@users.noreply.github.com> Date: Mon, 16 Sep 2024 12:21:19 +0200 Subject: [PATCH 2/3] Fix ruff linting --- assemblyai/extras.py | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/assemblyai/extras.py b/assemblyai/extras.py index 1ff6761..a0dea27 100644 --- a/assemblyai/extras.py +++ b/assemblyai/extras.py @@ -22,11 +22,7 @@ def __init__( class MicrophoneStream: - def __init__( - self, - sample_rate: int = 44_100, - device_index: int = None - ): + def __init__(self, sample_rate: int = 44_100, device_index: int = None): """ Creates a stream of audio from the microphone. @@ -144,4 +140,4 @@ def file_from_stream(data: BinaryIO) -> str: return api.upload_file( client=Client.get_default().http_client, audio_file=data, - ) \ No newline at end of file + ) From 96a9fe33093fd75f1894914fa7efc0da63a8e036 Mon Sep 17 00:00:00 2001 From: Patrick Loeber <98830383+ploeber@users.noreply.github.com> Date: Mon, 16 Sep 2024 12:24:45 +0200 Subject: [PATCH 3/3] Fix mypy error --- assemblyai/extras.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/assemblyai/extras.py b/assemblyai/extras.py index a0dea27..5086b70 100644 --- a/assemblyai/extras.py +++ b/assemblyai/extras.py @@ -1,5 +1,5 @@ import time -from typing import BinaryIO, Generator +from typing import BinaryIO, Generator, Optional from warnings import warn from . import api @@ -22,7 +22,7 @@ def __init__( class MicrophoneStream: - def __init__(self, sample_rate: int = 44_100, device_index: int = None): + def __init__(self, sample_rate: int = 44_100, device_index: Optional[int] = None): """ Creates a stream of audio from the microphone.