Skip to content

Instantly share code, notes, and snippets.

@darrenjrobinson
Last active July 23, 2021 16:55
Show Gist options
  • Save darrenjrobinson/fa763b14789f7fd8273dbb4be675bdfa to your computer and use it in GitHub Desktop.
Save darrenjrobinson/fa763b14789f7fd8273dbb4be675bdfa to your computer and use it in GitHub Desktop.
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