Skip to content

Commit d9165c1

Browse files
authored
Merge pull request #34 from yteraoka/selectable-tts-language
Make Text-to-Speech language selectable
2 parents f17261b + 144762e commit d9165c1

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,10 @@ Text-to-speech api needs to be enabled https://console.cloud.google.com/flows/en
244244
```
245245
$ go-chromecast tts <message_to_say> --google-service-account=/path/to/service/account.json
246246
```
247+
248+
For non en-US languages
249+
250+
```
251+
$ go-chromecast tts <message_to_say> --google-service-account=/path/to/service/account.json \
252+
--language-code ja-JP
253+
```

cmd/tts.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ var ttsCmd = &cobra.Command{
4040
return
4141
}
4242

43+
languageCode, _ := cmd.Flags().GetString("language-code")
44+
4345
b, err := ioutil.ReadFile(googleServiceAccount)
4446
if err != nil {
4547
fmt.Printf("unable to open google service account file: %v\n", err)
@@ -52,7 +54,7 @@ var ttsCmd = &cobra.Command{
5254
return
5355
}
5456

55-
data, err := tts.Create(args[0], b)
57+
data, err := tts.Create(args[0], b, languageCode)
5658
if err != nil {
5759
fmt.Printf("%v\n", err)
5860
return
@@ -86,4 +88,5 @@ var ttsCmd = &cobra.Command{
8688
func init() {
8789
rootCmd.AddCommand(ttsCmd)
8890
ttsCmd.Flags().String("google-service-account", "", "google service account JSON file")
91+
ttsCmd.Flags().String("language-code", "en-US", "text-to-speech Language Code (de-DE, ja-JP,...)")
8992
}

tts/tts.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const (
1515
timeout = time.Second * 10
1616
)
1717

18-
func Create(sentence string, serviceAccountKey []byte) ([]byte, error) {
18+
func Create(sentence string, serviceAccountKey []byte, languageCode string) ([]byte, error) {
1919
ctx, cancel := context.WithTimeout(context.Background(), timeout)
2020
defer cancel()
2121

@@ -29,7 +29,7 @@ func Create(sentence string, serviceAccountKey []byte) ([]byte, error) {
2929
InputSource: &texttospeechpb.SynthesisInput_Text{Text: sentence},
3030
},
3131
Voice: &texttospeechpb.VoiceSelectionParams{
32-
LanguageCode: "en-US",
32+
LanguageCode: languageCode,
3333
SsmlGender: texttospeechpb.SsmlVoiceGender_NEUTRAL,
3434
},
3535
AudioConfig: &texttospeechpb.AudioConfig{

0 commit comments

Comments
 (0)