Some checks failed
CodeQL / Analyze (go) (push) Successful in 6m28s
Docker Image / build-docker (push) Failing after 13m26s
Lint and Testing / lint (push) Successful in 11m17s
Lint and Testing / test (push) Successful in 11m17s
Lint and Testing / golangci (push) Successful in 2m40s
44 lines
842 B
Go
44 lines
842 B
Go
package transcode
|
|
|
|
import "fmt"
|
|
|
|
type Options struct {
|
|
Format string
|
|
SampleRate int
|
|
Channels int
|
|
Codec string
|
|
}
|
|
|
|
func WhisperOptions() Options {
|
|
return Options{
|
|
Format: FormatWAV,
|
|
SampleRate: 16000,
|
|
Channels: 1,
|
|
Codec: "pcm_s16le",
|
|
}
|
|
}
|
|
|
|
func (o *Options) ApplyDefaults() error {
|
|
spec, err := ResolveFormat(o.Format)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if o.Codec == "" {
|
|
o.Codec = spec.Codec
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func (o *Options) Validate() error {
|
|
if err := o.ApplyDefaults(); err != nil {
|
|
return err
|
|
}
|
|
if o.SampleRate < 0 || o.Channels < 0 {
|
|
return fmt.Errorf("sample_rate and channels must be >= 0")
|
|
}
|
|
if o.Channels > 8 {
|
|
return fmt.Errorf("channels must be <= 8")
|
|
}
|
|
return nil
|
|
}
|