1

I am using Android Studio and Google Cloud Text-To-Speech.

In SSML, I would like to play audio (see the Google documentation). I know that I could play that audio file with Java only but I would like to know why it is not working with SSML. This is what I have tried:

"<speak>What you hear is: <audio src='"+ getFilesDir() + "/scanner.mp3'></speak>"

I have also tried it with:

"<speak>What you hear is: <audio src='"+ R.raw.scanner +"'></speak>"

And also tried it with:

Uri uri = Uri.parse("android.resource://"+getPackageName()+"/raw/scanner.mp3");
String myString = "<speak>What you hear is: <audio src='"+ uri +"'></speak>";

If I run my application, I can hear "What you hear is" but not the audio.

The audio file (scanner.mp3) is in: src\main\res\raw

If I use a URL instead, it works fine. E.g.:

<speak>What you hear is: <audio src='https://s3.amazonaws.com/aws-website-resources-1183x/dice-die-roll.mp3' /></speak>

What's wrong with my code?

Reza Saadati
  • 5,018
  • 4
  • 27
  • 64

0 Answers0