-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
a7548a1
commit 85aec29
Showing
1 changed file
with
51 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/ringsaturn/azuretts" | ||
) | ||
|
||
type MultiSpeak struct { | ||
XML string | ||
} | ||
|
||
func (ms *MultiSpeak) ToXML() ([]byte, error) { | ||
return []byte(ms.XML), nil | ||
} | ||
|
||
var mess = `<speak version="1.0" xmlns="http://www.w3.org/2001/10/synthesis" xmlns:mstts="https://www.w3.org/2001/mstts" xml:lang="zh-CN"> | ||
<voice name="zh-CN-XiaomoNeural"> | ||
女儿看见父亲走了进来,问道: | ||
<mstts:express-as role="YoungAdultFemale" style="calm"> | ||
“您来的挺快的,怎么过来的?” | ||
</mstts:express-as> | ||
父亲放下手提包,说: | ||
<mstts:express-as role="OlderAdultMale" style="calm"> | ||
“刚打车过来的,路上还挺顺畅。” | ||
</mstts:express-as> | ||
</voice> | ||
</speak>` | ||
|
||
func main() { | ||
c := azuretts.NewClient( | ||
os.Getenv("SPEECH_KEY"), | ||
azuretts.Region(os.Getenv("SPEECH_REGION")), | ||
) | ||
|
||
b, err := c.GetSynthesize(context.Background(), &azuretts.SynthesisRequest{ | ||
Speak: &MultiSpeak{XML: mess}, | ||
Output: azuretts.AudioOutputFormat_Streaming_Audio16Khz32KbitrateMonoMp3, | ||
}) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if err := b.Error(); err != nil { | ||
panic(err) | ||
} | ||
err = os.WriteFile("multi.mp3", b.Body, 0644) | ||
if err != nil { | ||
panic(err) | ||
} | ||
} |