Merge pull request #334 from makaveli10/add_option_to_mute_audio_playback
Add option to mute audio playback for file input
This commit is contained in:
@@ -79,6 +79,7 @@ If you don't want this, set `--no_single_model`.
|
|||||||
- `output_recording_filename`: Specifies the `.wav` file path where the microphone input will be saved if `save_output_recording` is set to `True`.
|
- `output_recording_filename`: Specifies the `.wav` file path where the microphone input will be saved if `save_output_recording` is set to `True`.
|
||||||
- `max_clients`: Specifies the maximum number of clients the server should allow. Defaults to 4.
|
- `max_clients`: Specifies the maximum number of clients the server should allow. Defaults to 4.
|
||||||
- `max_connection_time`: Maximum connection time for each client in seconds. Defaults to 600.
|
- `max_connection_time`: Maximum connection time for each client in seconds. Defaults to 600.
|
||||||
|
- `mute_audio_playback`: Whether to mute audio playback when transcribing an audio file. Defaults to False.
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from whisper_live.client import TranscriptionClient
|
from whisper_live.client import TranscriptionClient
|
||||||
@@ -92,7 +93,8 @@ client = TranscriptionClient(
|
|||||||
save_output_recording=True, # Only used for microphone input, False by Default
|
save_output_recording=True, # Only used for microphone input, False by Default
|
||||||
output_recording_filename="./output_recording.wav", # Only used for microphone input
|
output_recording_filename="./output_recording.wav", # Only used for microphone input
|
||||||
max_clients=4,
|
max_clients=4,
|
||||||
max_connection_time=600
|
max_connection_time=600,
|
||||||
|
mute_audio_playback=False, # Only used for file input, False by Default
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
It connects to the server running on localhost at port 9090. Using a multilingual model, language for the transcription will be automatically detected. You can also use the language option to specify the target language for the transcription, in this case, English ("en"). The translate option should be set to `True` if we want to translate from the source language to English and `False` if we want to transcribe in the source language.
|
It connects to the server running on localhost at port 9090. Using a multilingual model, language for the transcription will be automatically detected. You can also use the language option to specify the target language for the transcription, in this case, English ("en"). The translate option should be set to `True` if we want to translate from the source language to English and `False` if we want to transcribe in the source language.
|
||||||
|
|||||||
+26
-7
@@ -46,6 +46,12 @@ class Client:
|
|||||||
port (int): The port number for the WebSocket server.
|
port (int): The port number for the WebSocket server.
|
||||||
lang (str, optional): The selected language for transcription. Default is None.
|
lang (str, optional): The selected language for transcription. Default is None.
|
||||||
translate (bool, optional): Specifies if the task is translation. Default is False.
|
translate (bool, optional): Specifies if the task is translation. Default is False.
|
||||||
|
model (str, optional): The whisper model to use (e.g., "small", "medium", "large"). Default is "small".
|
||||||
|
srt_file_path (str, optional): The file path to save the output SRT file. Default is "output.srt".
|
||||||
|
use_vad (bool, optional): Whether to enable voice activity detection. Default is True.
|
||||||
|
log_transcription (bool, optional): Whether to log transcription output to the console. Default is True.
|
||||||
|
max_clients (int, optional): Maximum number of client connections allowed. Default is 4.
|
||||||
|
max_connection_time (int, optional): Maximum allowed connection time in seconds. Default is 600.
|
||||||
"""
|
"""
|
||||||
self.recording = False
|
self.recording = False
|
||||||
self.task = "transcribe"
|
self.task = "transcribe"
|
||||||
@@ -285,7 +291,7 @@ class TranscriptionTeeClient:
|
|||||||
Attributes:
|
Attributes:
|
||||||
clients (list): the underlying Client instances responsible for handling WebSocket connections.
|
clients (list): the underlying Client instances responsible for handling WebSocket connections.
|
||||||
"""
|
"""
|
||||||
def __init__(self, clients, save_output_recording=False, output_recording_filename="./output_recording.wav"):
|
def __init__(self, clients, save_output_recording=False, output_recording_filename="./output_recording.wav", mute_audio_playback=False):
|
||||||
self.clients = clients
|
self.clients = clients
|
||||||
if not self.clients:
|
if not self.clients:
|
||||||
raise Exception("At least one client is required.")
|
raise Exception("At least one client is required.")
|
||||||
@@ -296,6 +302,7 @@ class TranscriptionTeeClient:
|
|||||||
self.record_seconds = 60000
|
self.record_seconds = 60000
|
||||||
self.save_output_recording = save_output_recording
|
self.save_output_recording = save_output_recording
|
||||||
self.output_recording_filename = output_recording_filename
|
self.output_recording_filename = output_recording_filename
|
||||||
|
self.mute_audio_playback = mute_audio_playback
|
||||||
self.frames = b""
|
self.frames = b""
|
||||||
self.p = pyaudio.PyAudio()
|
self.p = pyaudio.PyAudio()
|
||||||
try:
|
try:
|
||||||
@@ -391,6 +398,7 @@ class TranscriptionTeeClient:
|
|||||||
output=True,
|
output=True,
|
||||||
frames_per_buffer=self.chunk,
|
frames_per_buffer=self.chunk,
|
||||||
)
|
)
|
||||||
|
chunk_duration = self.chunk / float(wavfile.getframerate())
|
||||||
try:
|
try:
|
||||||
while any(client.recording for client in self.clients):
|
while any(client.recording for client in self.clients):
|
||||||
data = wavfile.readframes(self.chunk)
|
data = wavfile.readframes(self.chunk)
|
||||||
@@ -399,7 +407,10 @@ class TranscriptionTeeClient:
|
|||||||
|
|
||||||
audio_array = self.bytes_to_float_array(data)
|
audio_array = self.bytes_to_float_array(data)
|
||||||
self.multicast_packet(audio_array.tobytes())
|
self.multicast_packet(audio_array.tobytes())
|
||||||
self.stream.write(data)
|
if self.mute_audio_playback:
|
||||||
|
time.sleep(chunk_duration)
|
||||||
|
else:
|
||||||
|
self.stream.write(data)
|
||||||
|
|
||||||
wavfile.close()
|
wavfile.close()
|
||||||
|
|
||||||
@@ -661,10 +672,16 @@ class TranscriptionClient(TranscriptionTeeClient):
|
|||||||
host (str): The hostname or IP address of the server.
|
host (str): The hostname or IP address of the server.
|
||||||
port (int): The port number to connect to on the server.
|
port (int): The port number to connect to on the server.
|
||||||
lang (str, optional): The primary language for transcription. Default is None, which defaults to English ('en').
|
lang (str, optional): The primary language for transcription. Default is None, which defaults to English ('en').
|
||||||
translate (bool, optional): Indicates whether translation tasks are required (default is False).
|
translate (bool, optional): If True, the task will be translation instead of transcription. Default is False.
|
||||||
save_output_recording (bool, optional): Indicates whether to save recording from microphone.
|
model (str, optional): The whisper model to use (e.g., "small", "base"). Default is "small".
|
||||||
output_recording_filename (str, optional): File to save the output recording.
|
use_vad (bool, optional): Whether to enable voice activity detection. Default is True.
|
||||||
output_transcription_path (str, optional): File to save the output transcription.
|
save_output_recording (bool, optional): Whether to save the microphone recording. Default is False.
|
||||||
|
output_recording_filename (str, optional): Path to save the output recording WAV file. Default is "./output_recording.wav".
|
||||||
|
output_transcription_path (str, optional): File path to save the output transcription (SRT file). Default is "./output.srt".
|
||||||
|
log_transcription (bool, optional): Whether to log transcription output to the console. Default is True.
|
||||||
|
max_clients (int, optional): Maximum number of client connections allowed. Default is 4.
|
||||||
|
max_connection_time (int, optional): Maximum allowed connection time in seconds. Default is 600.
|
||||||
|
mute_audio_playback (bool, optional): If True, mutes audio playback during file playback. Default is False.
|
||||||
|
|
||||||
Attributes:
|
Attributes:
|
||||||
client (Client): An instance of the underlying Client class responsible for handling the WebSocket connection.
|
client (Client): An instance of the underlying Client class responsible for handling the WebSocket connection.
|
||||||
@@ -690,6 +707,7 @@ class TranscriptionClient(TranscriptionTeeClient):
|
|||||||
log_transcription=True,
|
log_transcription=True,
|
||||||
max_clients=4,
|
max_clients=4,
|
||||||
max_connection_time=600,
|
max_connection_time=600,
|
||||||
|
mute_audio_playback=False,
|
||||||
):
|
):
|
||||||
self.client = Client(
|
self.client = Client(
|
||||||
host, port, lang, translate, model, srt_file_path=output_transcription_path,
|
host, port, lang, translate, model, srt_file_path=output_transcription_path,
|
||||||
@@ -705,5 +723,6 @@ class TranscriptionClient(TranscriptionTeeClient):
|
|||||||
self,
|
self,
|
||||||
[self.client],
|
[self.client],
|
||||||
save_output_recording=save_output_recording,
|
save_output_recording=save_output_recording,
|
||||||
output_recording_filename=output_recording_filename
|
output_recording_filename=output_recording_filename,
|
||||||
|
mute_audio_playback=mute_audio_playback
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user