I'd like to use PowerShell with Amazon Polly to play streaming audio, without writing the audio to disk first, on the Windows 10 platform. Amazon Polly APIs return a System.IO.Stream object, containing the raw MP3 audio. Normally, you could write this to disk by using a System.IO.FileStream object, however I'm interested in playing audio without the extra disk I/O.
Question: How do I play MP3 audio on Windows 10, directly from an in-memory stream?
Generate Speech Audio with Amazon Polly
$result = Get-POLSpeech -OutputFormat mp3 -Text 'Hello Trevor' -VoiceId Astrid
Inspect Properties on Result Object
$result | Get-Member -MemberType Property
Results From Above Command
TypeName: Amazon.Polly.Model.SynthesizeSpeechResponse
Name MemberType Definition
---- ---------- ----------
AudioStream Property System.IO.Stream AudioStream {get;set;}
ContentLength Property long ContentLength {get;set;}
ContentType Property string ContentType {get;set;}
HttpStatusCode Property System.Net.HttpStatusCode HttpStatusCode {get;set;}
RequestCharacters Property int RequestCharacters {get;set;}
ResponseMetadata Property Amazon.Runtime.ResponseMetadata ResponseMetadata {get;set;}