@@ -0,0 +1,57 @@
|
|||||||
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
from whisper_live.client import TranscriptionClient
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument('--port', '-p',
|
||||||
|
type=int,
|
||||||
|
default=9090,
|
||||||
|
help="Websocket port to run the server on.")
|
||||||
|
parser.add_argument('--server', '-s',
|
||||||
|
type=str,
|
||||||
|
default='localhost',
|
||||||
|
help='hostname or ip address of server')
|
||||||
|
parser.add_argument('--files', '-f',
|
||||||
|
type=str,
|
||||||
|
nargs='+',
|
||||||
|
help='hostname or ip address of server')
|
||||||
|
parser.add_argument('--output_file', '-o',
|
||||||
|
type=str,
|
||||||
|
default='./output_recording.wav',
|
||||||
|
help='hostname or ip address of server')
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
# Validate audio files
|
||||||
|
valid_files = []
|
||||||
|
for file_path in args.files:
|
||||||
|
path = Path(file_path)
|
||||||
|
if path.exists() and path.is_file():
|
||||||
|
valid_files.append(str(path))
|
||||||
|
else:
|
||||||
|
print(f"Warning: File not found: {file_path}")
|
||||||
|
|
||||||
|
if not valid_files:
|
||||||
|
print("Error: No valid audio files found!")
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
print(f"Found {len(valid_files)} audio file(s) to stream:")
|
||||||
|
for file_path in valid_files:
|
||||||
|
print(f" - {file_path}")
|
||||||
|
|
||||||
|
for f in valid_files:
|
||||||
|
client = TranscriptionClient(
|
||||||
|
args.server,
|
||||||
|
args.port,
|
||||||
|
lang="en",
|
||||||
|
translate=False,
|
||||||
|
model="large-v3", # also support hf_model => `Systran/faster-whisper-small`
|
||||||
|
use_vad=False,
|
||||||
|
save_output_recording=False, # Only used for microphone input, False by Default
|
||||||
|
output_recording_filename=args.output_file, # Only used for microphone input
|
||||||
|
max_clients=4,
|
||||||
|
max_connection_time=600,
|
||||||
|
mute_audio_playback=True, # Only used for file input, False by Default
|
||||||
|
)
|
||||||
|
client(f)
|
||||||
@@ -420,6 +420,9 @@ class TranscriptionTeeClient:
|
|||||||
|
|
||||||
# read audio and create pyaudio stream
|
# read audio and create pyaudio stream
|
||||||
with wave.open(filename, "rb") as wavfile:
|
with wave.open(filename, "rb") as wavfile:
|
||||||
|
if self.mute_audio_playback:
|
||||||
|
self.stream = None
|
||||||
|
else:
|
||||||
self.stream = self.p.open(
|
self.stream = self.p.open(
|
||||||
format=self.p.get_format_from_width(wavfile.getsampwidth()),
|
format=self.p.get_format_from_width(wavfile.getsampwidth()),
|
||||||
channels=wavfile.getnchannels(),
|
channels=wavfile.getnchannels(),
|
||||||
@@ -428,6 +431,7 @@ class TranscriptionTeeClient:
|
|||||||
output=True,
|
output=True,
|
||||||
frames_per_buffer=self.chunk,
|
frames_per_buffer=self.chunk,
|
||||||
)
|
)
|
||||||
|
|
||||||
chunk_duration = self.chunk / float(wavfile.getframerate())
|
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):
|
||||||
@@ -448,6 +452,7 @@ class TranscriptionTeeClient:
|
|||||||
client.wait_before_disconnect()
|
client.wait_before_disconnect()
|
||||||
self.multicast_packet(Client.END_OF_AUDIO.encode('utf-8'), True)
|
self.multicast_packet(Client.END_OF_AUDIO.encode('utf-8'), True)
|
||||||
self.write_all_clients_srt()
|
self.write_all_clients_srt()
|
||||||
|
if self.stream:
|
||||||
self.stream.close()
|
self.stream.close()
|
||||||
self.close_all_clients()
|
self.close_all_clients()
|
||||||
|
|
||||||
|
|||||||
@@ -216,7 +216,8 @@ class TranscriptionServer:
|
|||||||
try:
|
try:
|
||||||
if self.backend.is_faster_whisper():
|
if self.backend.is_faster_whisper():
|
||||||
from whisper_live.backend.faster_whisper_backend import ServeClientFasterWhisper
|
from whisper_live.backend.faster_whisper_backend import ServeClientFasterWhisper
|
||||||
if faster_whisper_custom_model_path is not None and os.path.exists(faster_whisper_custom_model_path):
|
# model is of the form namespace/repo_name and not a filesystem path
|
||||||
|
if faster_whisper_custom_model_path is not None:
|
||||||
logging.info(f"Using custom model {faster_whisper_custom_model_path}")
|
logging.info(f"Using custom model {faster_whisper_custom_model_path}")
|
||||||
options["model"] = faster_whisper_custom_model_path
|
options["model"] = faster_whisper_custom_model_path
|
||||||
client = ServeClientFasterWhisper(
|
client = ServeClientFasterWhisper(
|
||||||
@@ -380,8 +381,6 @@ class TranscriptionServer:
|
|||||||
port (int): The port number to bind the server.
|
port (int): The port number to bind the server.
|
||||||
"""
|
"""
|
||||||
self.cache_path = cache_path
|
self.cache_path = cache_path
|
||||||
if faster_whisper_custom_model_path is not None and not os.path.exists(faster_whisper_custom_model_path):
|
|
||||||
raise ValueError(f"Custom faster_whisper model '{faster_whisper_custom_model_path}' is not a valid path.")
|
|
||||||
if whisper_tensorrt_path is not None and not os.path.exists(whisper_tensorrt_path):
|
if whisper_tensorrt_path is not None and not os.path.exists(whisper_tensorrt_path):
|
||||||
raise ValueError(f"TensorRT model '{whisper_tensorrt_path}' is not a valid path.")
|
raise ValueError(f"TensorRT model '{whisper_tensorrt_path}' is not a valid path.")
|
||||||
if single_model:
|
if single_model:
|
||||||
|
|||||||
Reference in New Issue
Block a user