Skip to content

added support for other file formats like srt and vtt #1050

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

Closed
wants to merge 3 commits into from
Closed
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
25 changes: 23 additions & 2 deletions src/openai/cli/_api/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,18 @@ def transcribe(args: CLITranscribeArgs) -> None:
# but we don't want to validate that here for forwards-compat
response_format=cast(Any, args.response_format),
)
print_model(model)

if args.response_format == 'json':
print_model(model)
elif args.response_format == 'srt':
# Handle SRT response format
print_model(model.get('srt'))
elif args.response_format == 'vtt':
# Handle VTT response format
print_model(model.get('vtt'))
else:
raise CLIError(f"Unsupported response format: {args.response_format}")
Comment on lines +79 to +88
Copy link
Collaborator

@RobertCraigie RobertCraigie Jan 15, 2024

Choose a reason for hiding this comment

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

Looks like you've got type checking errors.

I think this isn't quite correct as well, I think it should be this instead so that we don't always have to update this for every response_format.

        model = cast(
            "str | Transcription",
            get_client().audio.transcriptions.create(
                file=(args.file, buffer_reader),
                model=args.model,
                language=args.language or NOT_GIVEN,
                temperature=args.temperature or NOT_GIVEN,
                prompt=args.prompt or NOT_GIVEN,
                # casts required because the API is typed for enums
                # but we don't want to validate that here for forwards-compat
                response_format=cast(Any, args.response_format),
            ),
        )
        if isinstance(model, str):
            sys.stdout.write("\n" + model + "\n")
        else:
            print_model(model)

And the same applies below as well (replacing Transcription with Translation)



@staticmethod
def translate(args: CLITranslationArgs) -> None:
Expand All @@ -91,4 +102,14 @@ def translate(args: CLITranslationArgs) -> None:
# but we don't want to validate that here for forwards-compat
response_format=cast(Any, args.response_format),
)
print_model(model)

if args.response_format == 'json':
print_model(model)
elif args.response_format == 'srt':
# Handle SRT response format
print_model(model.get('srt'))
elif args.response_format == 'vtt':
# Handle VTT response format
print_model(model.get('vtt'))
else:
raise CLIError(f"Unsupported response format: {args.response_format}")