-
Notifications
You must be signed in to change notification settings - Fork 3
fix: solaria 3 correct endpoint and matching behavior with the openapi #27
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
Open
egenthon-cmd
wants to merge
2
commits into
main
Choose a base branch
from
fix/correct-endpoint-model
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,11 +31,11 @@ Examples: | |
| gladia transcribe podcast.mp3 --language en | ||
| gladia transcribe interview.mp3 --code-switching | ||
| gladia transcribe interview.mp3 --language en,fr,de | ||
| gladia transcribe call.wav --code-switch --language en -o json | ||
| gladia transcribe call.wav --cs --language en -o json | ||
| gladia transcribe call.wav --diarize -o srt | ||
| gladia transcribe podcast.mp3 --model solaria-3 | ||
| gladia transcribe podcast.mp3 --model solaria-3 --language en | ||
| gladia transcribe https://example.com/audio.mp3 -o json`, | ||
| Args: cobra.ExactArgs(1), | ||
| Args: validateTranscribeArgs, | ||
| RunE: func(cmd *cobra.Command, args []string) error { | ||
| if err := validateOutputFormat(outputFormat); err != nil { | ||
| return err | ||
|
|
@@ -45,12 +45,19 @@ Examples: | |
| return err | ||
| } | ||
|
|
||
| if err := validateLanguageFlag(languageFlag); err != nil { | ||
| return err | ||
| } | ||
|
|
||
| langs, err := types.ParseLanguages(languageFlag) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| codeSwitchSet := cmd.Flags().Changed("code-switching") || cmd.Flags().Changed("code-switch") | ||
| codeSwitchSet := cmd.Flags().Changed("code-switching") || cmd.Flags().Changed("cs") | ||
| if err := validateModelConfig(modelFlag, langs, codeSwitchSet, codeSwitching); err != nil { | ||
| return err | ||
| } | ||
| langConfig, err := buildLanguageConfig(langs, codeSwitching, codeSwitchSet) | ||
| if err != nil { | ||
| return err | ||
|
|
@@ -69,7 +76,7 @@ Examples: | |
| } | ||
|
|
||
| transcriptionReq := gladia.TranscriptionRequest{ | ||
| Model: modelFlag, | ||
| Model: normalizeModel(modelFlag), | ||
| LanguageConfig: langConfig, | ||
| Diarization: diarization, | ||
| } | ||
|
|
@@ -91,12 +98,37 @@ Examples: | |
| } | ||
|
|
||
| cmd.Flags().StringVarP(&outputFormat, "output", "o", "text", "Output format: text, json, json-full, srt, vtt") | ||
| cmd.Flags().StringVar(&languageFlag, "language", "", "Optional ISO 639-1 code(s), comma-separated (e.g. en or en,fr,de)") | ||
| cmd.Flags().BoolVar(&codeSwitching, "code-switching", false, "Enable code switching (detect language per utterance; independent of --language)") | ||
| cmd.Flags().BoolVar(&codeSwitching, "code-switch", false, "Alias for --code-switching") | ||
| cmd.Flags().StringVar(&languageFlag, "language", "", "Expected language(s), comma-separated (e.g. en or en,fr,de); does not enable code switching") | ||
| const codeSwitchingUsage = "Re-detect language on each utterance (for mixed-language audio; solaria-1 only)" | ||
| cmd.Flags().BoolVar(&codeSwitching, "cs", false, codeSwitchingUsage) | ||
| cmd.Flags().BoolVar(&codeSwitching, "code-switching", false, codeSwitchingUsage) | ||
| cmd.Flags().Lookup("cs").Hidden = true | ||
| cmd.Flags().Lookup("code-switching").Hidden = true | ||
| cmd.Flags().BoolVarP(&verbose, "verbose", "v", false, "Show progress while transcribing") | ||
| cmd.Flags().BoolVar(&diarization, "diarize", false, "Enable speaker diarization") | ||
| cmd.Flags().StringVar(&modelFlag, "model", "", "STT model: solaria-1 or solaria-3 (default: API default)") | ||
| cmd.Flags().StringVar(&modelFlag, "model", "", "STT model: solaria-1 or solaria-3 (solaria-3 accepts at most one --language: en, fr, de, es, or it)") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not at most, it accepts only one |
||
|
|
||
| cmd.SetUsageTemplate(`Usage:{{if .Runnable}} | ||
| {{.UseLine}}{{end}}{{if .HasAvailableSubCommands}} | ||
| {{.CommandPath}} [command]{{end}}{{if gt (len .Aliases) 0}} | ||
|
|
||
| Aliases: | ||
| {{.NameAndAliases}}{{end}}{{if .HasExample}} | ||
|
|
||
| Examples: | ||
| {{.Example}}{{end}}{{if .HasAvailableLocalFlags}} | ||
|
|
||
| Flags: | ||
| --cs, --code-switching — ` + codeSwitchingUsage + ` | ||
| {{.LocalFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasAvailableInheritedFlags}} | ||
|
|
||
| Global Flags: | ||
| {{.InheritedFlags.FlagUsages | trimTrailingWhitespaces}}{{end}}{{if .HasHelpSubCommands}} | ||
|
|
||
| Additional help topics:{{range .Commands}}{{if .IsAdditionalHelpTopicCommand}} | ||
| {{rpad .CommandPath .CommandPathPadding}} {{.Short}}{{end}}{{end}}{{end}}{{if .HasAvailableSubCommands}} | ||
|
|
||
| Use "{{.CommandPath}} [command] --help" for more information about a command.{{end}}`) | ||
|
|
||
| return cmd | ||
| } | ||
|
|
@@ -130,6 +162,7 @@ func validateOutputFormat(format string) error { | |
| } | ||
|
|
||
| func validateModel(model string) error { | ||
| model = normalizeModel(model) | ||
| if model == "" { | ||
| return nil | ||
| } | ||
|
|
@@ -141,6 +174,125 @@ func validateModel(model string) error { | |
| } | ||
| } | ||
|
|
||
| var solaria3Languages = map[types.Language]bool{ | ||
| types.LanguageEn: true, | ||
| types.LanguageFr: true, | ||
| types.LanguageDe: true, | ||
| types.LanguageEs: true, | ||
| types.LanguageIt: true, | ||
| } | ||
|
|
||
| func validateModelConfig(model string, langs []types.Language, codeSwitchSet, codeSwitching bool) error { | ||
| model = normalizeModel(model) | ||
| if model != "solaria-3" { | ||
| return nil | ||
| } | ||
| if codeSwitchSet && codeSwitching { | ||
| return fmt.Errorf("solaria-3 does not support code switching (use solaria-1 instead)") | ||
| } | ||
| switch len(langs) { | ||
| case 0: | ||
| return nil | ||
| case 1: | ||
| if !solaria3Languages[langs[0]] { | ||
| return fmt.Errorf("solaria-3 does not support language %q (use en, fr, de, es, or it)", langs[0]) | ||
| } | ||
| return nil | ||
| default: | ||
| codes := make([]string, len(langs)) | ||
| for i, lang := range langs { | ||
| codes[i] = string(lang) | ||
| } | ||
| return fmt.Errorf("solaria-3 accepts only one language, got %d (%s); use solaria-1 for multi-language", len(langs), strings.Join(codes, ", ")) | ||
| } | ||
| } | ||
|
|
||
| func normalizeModel(model string) string { | ||
| model = strings.TrimSpace(strings.ToLower(model)) | ||
| return strings.ReplaceAll(model, " ", "-") | ||
| } | ||
|
|
||
| func validateTranscribeArgs(cmd *cobra.Command, args []string) error { | ||
| if len(args) == 1 { | ||
| return nil | ||
| } | ||
|
|
||
| langFlag, _ := cmd.Flags().GetString("language") | ||
| langFlag = strings.TrimSpace(langFlag) | ||
|
|
||
| // gladia transcribe --language en fr meeting.wav | ||
| if len(args) == 2 && isKnownLanguageCode(args[0]) && !isKnownLanguageCode(args[1]) && langFlag != "" { | ||
| return spaceSeparatedLanguageError(joinLanguageCodes(langFlag, args[0])) | ||
| } | ||
|
|
||
| // gladia transcribe meeting.wav --language en fr | ||
| var extraLangs []string | ||
| for _, arg := range args[1:] { | ||
| if isKnownLanguageCode(arg) { | ||
| extraLangs = append(extraLangs, arg) | ||
| } | ||
| } | ||
| if langFlag != "" && len(extraLangs) > 0 { | ||
| return spaceSeparatedLanguageError(joinLanguageCodes(append([]string{langFlag}, extraLangs...)...)) | ||
| } | ||
|
|
||
| return fmt.Errorf("accepts 1 arg(s), received %d", len(args)) | ||
| } | ||
|
|
||
| func validateLanguageFlag(s string) error { | ||
| s = strings.TrimSpace(s) | ||
| if s == "" || strings.Contains(s, ",") { | ||
| return nil | ||
| } | ||
| if strings.Contains(s, " ") { | ||
| parts := strings.Fields(s) | ||
| if len(parts) > 1 && allKnownLanguageCodes(parts) { | ||
| return spaceSeparatedLanguageError(parts) | ||
| } | ||
| } | ||
| return nil | ||
| } | ||
|
|
||
| func spaceSeparatedLanguageError(codes []string) error { | ||
| normalized := make([]string, 0, len(codes)) | ||
| for _, code := range codes { | ||
| code = strings.ToLower(strings.TrimSpace(code)) | ||
| if code != "" { | ||
| normalized = append(normalized, code) | ||
| } | ||
| } | ||
| return fmt.Errorf("--language expects comma-separated codes (e.g. --language %s), not spaces", strings.Join(normalized, ",")) | ||
| } | ||
|
|
||
| func joinLanguageCodes(codes ...string) []string { | ||
| out := make([]string, 0, len(codes)) | ||
| for _, code := range codes { | ||
| code = strings.ToLower(strings.TrimSpace(code)) | ||
| if code != "" { | ||
| out = append(out, code) | ||
| } | ||
| } | ||
| return out | ||
| } | ||
|
|
||
| func allKnownLanguageCodes(codes []string) bool { | ||
| for _, code := range codes { | ||
| if !isKnownLanguageCode(code) { | ||
| return false | ||
| } | ||
| } | ||
| return len(codes) > 0 | ||
| } | ||
|
|
||
| func isKnownLanguageCode(code string) bool { | ||
| code = strings.TrimSpace(code) | ||
| if code == "" { | ||
| return false | ||
| } | ||
| _, err := types.ParseLanguage(code) | ||
| return err == nil | ||
| } | ||
|
|
||
| func isHTTPURL(s string) bool { | ||
| lower := strings.ToLower(s) | ||
| return strings.HasPrefix(lower, "http://") || strings.HasPrefix(lower, "https://") | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's should be -cs instead, wdyt?