-
Notifications
You must be signed in to change notification settings - Fork 0
/
languages.go
37 lines (30 loc) · 937 Bytes
/
languages.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package suzu
import (
"fmt"
"github.com/aws/aws-sdk-go/service/transcribestreamingservice"
)
var (
ErrMissingAudioStreamingLanguageCode = fmt.Errorf("MISSING-SORA-AUDIO-STREAMING-LANGUAGE-CODE")
ErrUnsupportedLanguageCode = fmt.Errorf("UNSUPPORTED-LANGUAGE-CODE")
ErrUnsupportedService = fmt.Errorf("UNSUPPORTED-SERVICE")
)
func GetLanguageCode(serviceType, lang string, f func(string) (string, error)) (string, error) {
if lang == "" {
return "", ErrMissingAudioStreamingLanguageCode
}
if f != nil {
return f(lang)
}
switch serviceType {
case "aws":
for _, languageCode := range transcribestreamingservice.LanguageCode_Values() {
if languageCode == lang {
return languageCode, nil
}
}
return "", fmt.Errorf("%w: %s", ErrUnsupportedLanguageCode, lang)
case "gcp", "test", "dump":
return lang, nil
}
return "", fmt.Errorf("%w: %s", ErrUnsupportedService, serviceType)
}