1

My application needs to run a silent mp3 in background. I use TTS synthesizetofile() to convert text to mp3 and TTS playsilence() for playing silence. While I can easily convert normal text to mp3 I cant figure out an easy way to play silence.

For those who would suggest don't play anything for x duration and that will be silence...it will not solve my objective. Because if nothing is being played that would allow other sound application to assume that nothing is being played while here I need a silent pause. Secondly, when nothing is being played, android by default shuts down the application.

Also, the solution is not to create a silent mp3 file manually and put into the application because the pause keeps varying and also dependent on values chosen by the user.

Also, TTS playsilence will not do the job because android does not consider it as background music application and shuts it down in like 5 seconds.

Thanks!

mohsyn
  • 186
  • 12
  • You could have your app play silence always using a separate audiotrack instance. – Nerdy Bunz Oct 29 '22 at 09:35
  • that would not work because it would show as playing when actually there WILL be a period when it is not playing and should allow other apps to take over... – mohsyn Oct 29 '22 at 09:42
  • OK, but a new question: why do you need to use the tts to create the silent file? What are what are you using to the play the files? Why cant you just create your own method like byte[] createSilentWAV(int milliseconds)? Are you using java? – Nerdy Bunz Oct 29 '22 at 20:19
  • @NerdyBunz that's a lot of questions for a question which is already marked as solved. – mohsyn Oct 29 '22 at 21:16
  • Yes but it created a new problem for you in your new question, so I was thinking there might be a better way to approach it from the beginning. – Nerdy Bunz Oct 29 '22 at 21:23
  • sure - so why TTS because I am already using a TTS library and did not want to burden app with another lib just for creating a silent audio file. I am not using my own method because I am not very well versed with java. I am using a RAD tool which has its own syntax and converts to java and compiles. – mohsyn Oct 29 '22 at 21:38

1 Answers1

0

I found a solution myself and sharing for those who would come looking for it here...

Use the same TTS.synthesizetofile() method but instead of text use the text in code below:

<speak version="1.1" ><break time="1500ms" /></speak>

replace 1500ms here with any duration you want either in seconds or milliseconds like "3s" or "3000ms"

mohsyn
  • 186
  • 12