Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MP3 streaming in C# .NET 4.5.1 MVC 5.2.2 on Samsung 6S

I have to use a TTS (Text to Speak) SaaS from ReadSpeaker in order to add audio to the application that I am developing.

Now the basic SCAPI account that we are currently using has a basic setup were you simply set a URL and get a MP3 stream back that we need to output. Because the service key is in the URL we can't use it in the front end so we need to stream the files through our servers.

Everything worked fine until I tested the development code on the Samsung 6S. Where it did not play at all, however the services own link works i.e. this works:

<audio controls>
    <source 
        src="http://tts.readspeaker.com/a/speak?key=[ServiceKey]&lang=en_uk&voice=Female01&audioformat=mp3&volume=200&text=test text 2"
        type="audio/mp3">
        Your browser does not support the audio element.
</audio>

while the exact same code through our servers does not on Samsung 6S with the same link as the stream source in the controller.

I've gone through several different ways of streaming the file on the server but simply fallen flat each time in Samsung 6S (brand new out of the box no mods).

Here is the code I have used.

Void controller:

string url = "http://tts.readspeaker.com/a/speak?key=[ServiceKey]&lang=en_uk&voice=Female01&audioformat=mp3&volume=200&text=test text 2";

HttpWebRequest HttpWRequest = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)HttpWRequest.GetResponse();

Stream stream = response.GetResponseStream();

MemoryStream ms = new MemoryStream();
stream.CopyTo(ms);

Response.AddHeader("Content-Type", response.ContentType);
Response.AddHeader("Content-Length", response.ContentLength.ToString());
Response.AddHeader("Access-Control-Allow-Origin", "*");
Response.AddHeader("Connection", "close");

Response.Flush();

audioData = ms.ToArray();
Response.BinaryWrite(audioData);

Response.End();

Standard FileStreamResult where I take the above code's MemoryStream and send through it i.e. with a FileStreamResult controller instead of setting the headers manually:

return new FileStreamResult(ms, response.ContentType);

and even a modified FileStreamResult I found here that allows for actual streaming of the URL without the need to download it to the server.

I've also used this method to get the byte data from ReadSpeaker:

byte[] audioData;
using (WebClient client = new WebClient())
{
    audioData = client.DownloadData("http://tts.readspeaker.com/a/speak?key=[ServiceKey]&lang=en_uk&voice=Female01&audioformat=mp3&volume=200&text=test text 2");
}

And then myriad of ways to output it, but always the result is the same, works fine on everything else (even IE7, not with audio tags, but still) but not with Samsung 6S.

I do not know I must be missing something very basic here, because everything I've tried works just fine on everything else but on the Samsung 6S nothing. Even on other high end Androids like the LG G4 it works but on the 6S... nothing, jet the direct service link in an Audio tag works just fine?

So I know I must be doing something wrong here, any ideas?

like image 672
Idra Avatar asked Dec 15 '15 20:12

Idra


1 Answers

Coding appears to be fine.

Samsung has its own TTS, which might be interference with your own. you might want to play with it,either uninstall it or enable it. http://www.samsung.com/in/support/skp/htg/16082

like image 178
Ashish Rawat Avatar answered Nov 11 '22 12:11

Ashish Rawat