Question

I build a helper class with a couple of methods I need for text to speech synthesis however I cannot manage to initiate a TextToSpeech object without getApplicationContext(). How do I initiate it?

public class SpeechHelper {
    private TextToSpeech speech;
    private Context context = null;

    public SpeechHelper(Context context)
    {
        this.context = context;
        speech = new TextToSpeech(getApplicationContext(), context);
    }
Was it helpful?

Solution

Here's your code with the interface implemented:

public class SpeechHelper implements OnInitListener {
    private TextToSpeech speech;
    private Context context = null;

    public SpeechHelper(Context context)
    {
        this.context = context;
        speech = new TextToSpeech(context, this);
    }

    @Override
    public void onInit(int status) {
        // TextToSpeech engine is initialized
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top