How to pause TextToSpeech along with the activity? - android

While developing TextToSpeech got a doubt that if we pause the activity how can we pause the TextToSpeeh along with the activity...If we resume the activity the text to speech will start where it has stopped previously...
How can we achieve this?
Thanks..

The TTS SDK doesn't have any pause functionality that I know of. But you could use synthesizeToFile() to create an audio file that contains the TTS output. Then, you would use a MediaPlayer object to play, pause, and stop playing the file. Depending on how long the text string is, it might take a little longer for audio to be produced because the synthesizeToFile() function would have to complete the entire file before you could play it, but this delay should be acceptable for most applications.

Related

Create a silent mp3 using TTS

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!
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"

Process music being played by another Android app?

I'm looking to make an Android app that can process music being played by another app. More specifically I want to analyze the raw audio. I've done some research and looked around, but I'm beginning to think this isn't possible, and maybe for good reason.
Does anyone have any ideas on how I might be able to achieve this capability?
as your requirement is to analyse all aps audio and want to process raw audio too.only one possibility is there which is to start recorder in background service and analyse audio all the time like many of the call recorder app on play store is doing to record a call.
it does have some drawbacks too
background noise
you will not able to know when music starts and when stops.

Playing music in PlayN: how to pause, resume?

I am playing some background music in my PlaynN game. Everything is fine except it does not pause when the activity is sent to the background. Music still plays when the game is not playing.
I can use Sound.stop() and Sound.play() whenever the window focus changes but then the music restarts from the beginning. I can instead use setVolume(0) and setVolume(1), but it still doesn't sound the way it is supposed to.
I cannot find a working example. I am currently considering the use of a platform specific music player.
Many thanks
To my knowledge, PlayN doesn't support pausing/resuming a Sound, probably because not all platforms support this. However, you might want to take a look at the Android-specific implementation of AndroidAudio, which seems to use a SoundPool backend. The GameActivity seems to already pause and resume sounds when the window gains/looses focus, so I'm not sure why it's not working for you - I believe it has for me. You might try calling these methods manually to test that they work, and if not consider filing an issue.

How to make a variable length sound in Android

I am trying to make an app that plays a sound like a piano organ. When the user presses a button it will play a piano-like sound. The difficulty is that the user could hold their finger down for any length of time. When they lift their finger off the should fade rather than stop abruptly.
I've played with SoundPool and Media Player but they don't seem suitable.
There are a lot of piano apps out there... does anyone know how they solve this problem?
You'll want to use the AudioTrack class. The basic usage is to write your sound data using AudioTrack's write() method for whatever duration that you want it to be heard. You'll need to use a separate thread for each simultaneous voice that you want to "play".
Here's the AudioTrack reference page and here's a blog entry where the author does a nice job of showing what to do without a lot of distractions.

Playing music files in Android

I have a list of music files that should be played with my Android application. Actually user selects a list of files to be played for a specified time, and then clicks on 'start button'. Please tell me how I can implement it so that the following requirements are met:
The program should work, even if power button is pressed or the display is turned off.
Music files should be played one by one.
In order that the music continue after your application activities exit, you need to implement the playing itself as a Service (specifically, a started service). For playing the music, take a look at MediaPlayer. There is a discussion of using a MediaPlayer in a Service in the Media Player guide topic.
To play audio files, you can use Android's MediaPlayer class.
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(audioFilePath);
mp.prepare();
mp.start();
This code snippet will load and play a single audio file. Take a look at the documentation for MediaPlayer to figure out how you might be able to leverage it for what you're trying to accomplish specifically.

Categories

Resources