Skip to content
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

stdin support #69

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
23 changes: 16 additions & 7 deletions src/whisper_ctranslate2/whisper_ctranslate2.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import argparse
import os
import tempfile
from .transcribe import Transcribe, TranscriptionOptions
from .languages import LANGUAGES, TO_LANGUAGE_CODE, from_language_to_iso_code
import numpy as np
import warnings
from typing import Union, List
from typing import BinaryIO, Union, List
from .writers import get_writer
from .version import __version__
from .live import Live
Expand Down Expand Up @@ -466,11 +467,18 @@ def main():
)

if not live_transcribe and len(audio) == 0:
sys.stderr.write("You need to specify one or more audio files\n")
sys.stderr.write(
"Use `whisper-ctranslate2 --help` to see the available options.\n"
)
return
pipe_data: BinaryIO = sys.stdin.buffer.read()
if len(pipe_data) == 0:
sys.stderr.write("You need to specify one or more audio files or pipe in audio data\n")
sys.stderr.write(
"Use `whisper-ctranslate2 --help` to see the available options.\n"
)
return
else:
with tempfile.NamedTemporaryFile(mode='wb', delete=False) as temp_file:
temp_file.write(pipe_data)
audio = [temp_file.name]


word_options = ["highlight_words", "max_line_count", "max_line_width"]
if not options.word_timestamps:
Expand Down Expand Up @@ -553,10 +561,11 @@ def main():
local_files_only,
)


for audio_path in audio:
if verbose and len(audio) > 1:
print(f"\nFile: '{audio_path}'")

result = transcribe.inference(
Copy link
Collaborator

@jordimas jordimas Nov 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please install black and run pip python -m black *.py to make sure that formatting is good and unnecessary additional spaces are removed if not needed.

audio_path,
task,
Expand Down