-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
413 additions
and
33 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
"golint", | ||
"govet", | ||
"unstaged", | ||
"untracked" | ||
"untracked", | ||
"webm" | ||
] | ||
} |
This file contains 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 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 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 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 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 |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. | ||
|
||
package common | ||
|
||
// SynthesisVoiceGender defines the gender of a synthesis voice. | ||
type SynthesisVoiceGender int | ||
|
||
const ( | ||
// GenderUnknown means the gender is unknown. | ||
GenderUnknown SynthesisVoiceGender = 0 | ||
|
||
// Female indicates female. | ||
Female SynthesisVoiceGender = 1 | ||
|
||
// Male indicates male. | ||
Male SynthesisVoiceGender = 2 | ||
) |
This file contains 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 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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. | ||
|
||
// Package synthesizer provides samples of text-to-speech | ||
package synthesizer |
This file contains 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 |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE.md file in the project root for full license information. | ||
|
||
package synthesizer | ||
|
||
import ( | ||
"bufio" | ||
"fmt" | ||
"io" | ||
"os" | ||
"strings" | ||
"time" | ||
|
||
"github.com/Microsoft/cognitive-services-speech-sdk-go/speech" | ||
) | ||
|
||
func SynthesisToAudioDataStream(subscription string, region string, file string) { | ||
config, err := speech.NewSpeechConfigFromSubscription(subscription, region) | ||
if err != nil { | ||
fmt.Println("Got an error: ", err) | ||
return | ||
} | ||
defer config.Close() | ||
speechSynthesizer, err := speech.NewSpeechSynthesizerFromConfig(config, nil) | ||
if err != nil { | ||
fmt.Println("Got an error: ", err) | ||
return | ||
} | ||
defer speechSynthesizer.Close() | ||
|
||
speechSynthesizer.SynthesisStarted(synthesizeStartedHandler) | ||
speechSynthesizer.Synthesizing(synthesizingHandler) | ||
speechSynthesizer.SynthesisCompleted(synthesizedHandler) | ||
speechSynthesizer.SynthesisCanceled(cancelledHandler) | ||
|
||
for { | ||
fmt.Printf("Enter some text that you want to speak, or enter empty text to exit.\n> ") | ||
text, _ := bufio.NewReader(os.Stdin).ReadString('\n') | ||
text = strings.TrimSuffix(text, "\n") | ||
if len(text) == 0 { | ||
break | ||
} | ||
|
||
// StartSpeakingTextAsync sends the result to channel when the synthesis starts. | ||
task := speechSynthesizer.StartSpeakingTextAsync(text) | ||
var outcome speech.SpeechSynthesisOutcome | ||
select { | ||
case outcome = <-task: | ||
case <-time.After(60 * time.Second): | ||
fmt.Println("Timed out") | ||
return | ||
} | ||
defer outcome.Close() | ||
if outcome.Error != nil { | ||
fmt.Println("Got an error: ", outcome.Error) | ||
return | ||
} | ||
|
||
// in most case we want to streaming receive the audio to lower the latency, | ||
// we can use AudioDataStream to do so. | ||
stream, err := speech.NewAudioDataStreamFromSpeechSynthesisResult(outcome.Result) | ||
defer stream.Close() | ||
if err != nil { | ||
fmt.Println("Got an error: ", err) | ||
return | ||
} | ||
|
||
var all_audio []byte | ||
audio_chunk := make([]byte, 2048) | ||
for { | ||
n, err := stream.Read(audio_chunk) | ||
|
||
if err == io.EOF { | ||
break | ||
} | ||
|
||
all_audio = append(all_audio, audio_chunk[:n]...) | ||
} | ||
|
||
fmt.Printf("Read [%d] bytes from audio data stream.\n", len(all_audio)) | ||
} | ||
} |
Oops, something went wrong.