DareToExplore
DareToExplore

Reputation: 259

Azure Cognitive Services (Text to Speech) and Audio Issue in IE (Invalid source)

I am new to Azure services and I need a bit of a guidance here.

Background

I am using the Azure Text-to-Speech service to convert text to speech and that data returned from API is saved in Azure BLOB storage. This happens via a schedule which keeps identifying the new text, converts it and saves to Azure storage. When the user logs in the application, there is an HTML5 audio tag which is linked to that Azure saved BLOB URL and it auto plays the converted text.

I have followed the samples from these APIs and everything is working fine. The only issue is the Audio DOES NOT play in IE 11. It always gives the "InValid Source" error. It works well in Chrome, FF.

Google is loaded with many solutions for this particular issue and I have almost tried them all.

1) Using MP3 type instead of .WAV file that I was using earlier

2) Explicility closing the audio tags

3) Checked the header response returned in the browser. That also is correct.(Audio/mpeg)

I also tried adding a dummy .mp3 file in storage and playing it back from storage. It works fine. So, I strongly doubt it is the content returned from Text-to-speech API service and getting stored in Azure is the issue.

Here is some sample code of that part:

Task<HttpResponseMessage> task = TextToSpeechService.ConvertTextToSpeech(textToConvert, gender, voice, this.DataContext);
task.Wait();
if (task.Result.IsSuccessStatusCode && task.Result.Content != null)
{
    Task<byte[]> ttsResult = task.Result.Content.ReadAsByteArrayAsync();
    ttsResult.Wait();
    if (ttsResult.Result != null)
    {
        try
        {
            // Save the audio to Azure Storage
            var fileName = "test.mp3";
            Task<string> storageTask = BlobStorage.CreateBlockBlob("texttospeechsample", fileName, ttsResult.Result, "audio/mpeg");
            storageTask.Wait();
            if (!string.IsNullOrEmpty(storageTask.Result))
            {
                // Save the details
                SaveAudioStorageDetails(storageTask.Result);
            }
        }
        catch (Exception ex)
        {
            throw new Exception("An error occurred while saving audio to azure storage." + ex.Message);
        }
    }
}

Can anyone please suggest what else should I try and where I should troubleshoot further?

Thank you.

Upvotes: 1

Views: 1715

Answers (1)

DareToExplore
DareToExplore

Reputation: 259

Ok, I found the issue here. As I was checking the Text-To-Speech API docs further, I saw there is one output parameter in request header. X-Microsoft-OutputFormat defines the type of audio that will be returned from the API.

https://learn.microsoft.com/en-us/azure/cognitive-services/speech-service/rest-text-to-speech#audio-outputs

Since I was following the API samples, the X-Microsoft-OutputFormat it used was riff-24khz-16bit-mono-pcm.This should be in alignment with the audio type that we want to save and play back. Other browsers were able to probably convert it and play back properly but IE used to always give "Invalid Source" error.

In my case, changing it to audio-24khz-160kbitrate-mono-mp3 worked fine and it is saving and playing back the audio properly in IE as well.

Hope this helps someone.

Upvotes: 1

Related Questions