Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert Speech to Text with PowerShell and Azure Cognitive Services STT
# Audio Phrase
$audiofile = Get-ChildItem "C:\temp\speech2convert.wav"
# Read audio into byte array
$audioBytes = [System.IO.File]::ReadAllBytes($audiofile)
# API Key
$key1 = "your api key"
# Conversion URI
$conversionURI = "https://speech.platform.bing.com/speech/recognition/interactive/cognitiveservices/v1?language=en-us&format=detailed"
# Conversion Headers
$Headers = @{
'Ocp-Apim-Subscription-Key' = $key1;
'Transfer-Encoding' = 'chunked';
'Content-type' = 'audio/pcm; codec=audio/pcm; samplerate=16000'
}
# Convert
$TextResponse = Invoke-RestMethod -Method POST -Uri $conversionURI -Headers $Headers -Body $audioBytes
# Result
$TextResponse.NBest.Lexical
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment