Question

In java, using android-19, this works fine:

import android.speech.tts.TextToSpeech.Engine;

But in scala:

import android.speech.tts.TextToSpeech.Engine
                                       ^
error: value Engine is not a member of object android.speech.tts.TextToSpeech

This is weird because I can import EngineInfo without problems, but it does not recognize the class Engine, although it is clearly in the android.jar

Any fix or workaround? Is this a scala issue? I'm developping on Eclipse 3.7 using AndroidProguardScala v51 and Scala IDE version 3.0.1

EDIT

The context in which I am using this is for example the following:

if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
  mTts = new TextToSpeech(this, mTtsListener)
}
Was it helpful?

Solution

Unfortunately, TextToSpeech.Engine is declared non-static which means something like this:

public class TextToSpeech {
    public class Engine {
        // ...
    }
    // ...
}

So according to this, you can't access it. Here's my workaround using a wrapper:

object ConstantsWrapper {
  private val cls = classOf[TextToSpeech#Engine]
  def apply(fieldName: String) = cls.getDeclaredField(fieldName).get(null)
                                    .toString

  val CHECK_VOICE_DATA_PASS = apply("CHECK_VOICE_DATA_PASS")
  // Insert more here
}

if (resultCode == ConstantsWrapper.CHECK_VOICE_DATA_PASS) {
  mTts = new TextToSpeech(this, mTtsListener)
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top