Skip to content

Instantly share code, notes, and snippets.

@AlexanderHolmeset
Last active October 18, 2023 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlexanderHolmeset/8194ba19eb3258905bcc52b0659da1fa to your computer and use it in GitHub Desktop.
Save AlexanderHolmeset/8194ba19eb3258905bcc52b0659da1fa to your computer and use it in GitHub Desktop.
VoiceStyle
$AzureSpeechSubscriptionKey = 'enter your key here'
$AzureSpeechRegion = 'norwayeast'
$Language = 'en-us'
$VoiceName = 'en-US-JennyNeural'
$Style = 'whispering'
$FetchTokenHeader = @{
'Content-type'='application/x-www-form-urlencoded';
'Content-Length'= '0';
'Ocp-Apim-Subscription-Key' = $AzureSpeechSubscriptionKey
}
$OAuthToken = Invoke-RestMethod -Method POST -Uri https://$AzureSpeechRegion.api.cognitive.microsoft.com/sts/v1.0/issueToken -Headers $FetchTokenHeader
# show the token received
$OAuthToken
$MyHeader = @{"Authorization" = "Bearer $OAuthToken";
"X-Microsoft-OutputFormat" = "audio-16khz-128kbitrate-mono-mp3" }
$uri = "https://$AzureSpeechRegion.tts.speech.microsoft.com/cognitiveservices/v1"
$Body = @"
<speak version='1.0' xml:lang='$Language'>
<voice name="$VoiceName" style="$Style" styledegree="2">
Hi my name is Jenny. I am a neural voice. This is what I sound like when I have a American voice and im whispering.
</voice>
</speak>
"@
Invoke-RestMethod -Method Post -ContentType "application/ssml+xml" -Headers $MyHeader -Body $Body -Uri $uri -OutFile "audio1.wav"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment