As an experiment, and as a way to force myself to understand the ins and outs of how tts works on Android, I thought it might be interesting to copy the source code for the TextToSpeech class into a new class in my project and rename it (and it's package name) to that of my project.
This of course results in many classes getting highlighted in red and needing to be re-attached and brought into my project as well.
So I began the process of repeating the same procedure -- copying the source of each missing class into a new class in my project -- which leads to more missing classes within that new class.
I was expecting these errors to happen, but in theory I was hoping it would be possible to graft the whole android.tts.* "tree" (or whatever parts were necessary in order to make the TextToSpeech class function) into my project.
Here's my code to illustrate:
MainActivity.java:
public class MainActivity extends AppCompatActivity {
// notice that this not android.speech.tts.TextToSpeech class, but a local copy of it.
MyTextToSpeech tts;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tts = new MyTextToSpeech(getApplicationContext(), new MyTextToSpeech.OnInitListener() {
@Override
public void onInit(int i) {
if (i == TextToSpeech.SUCCESS) {
begin();
}
else {
Log.i("XXX", "init failed");
}
}
}, "com.google.android.tts");
}
private void begin() {
Log.i("XXX", "It seems to have initialized!");
}
}
I've gotten rid of most of the errors in my "custom" TextToSpeech class (plz just assume this error is the only one remaining), but there is this one class that I can't seem to pull into the project: ITextToSpeechService:
Apparently this is a hidden/internal "aidl" file the source of which is here.
I tried pasting it in a new folder named "aidl" (following this answer) and it "worked" in the sense that it existed in the aidl folder without errors, but when trying to compile it using gradle\tasks\other\compileDebugAidl, I got this error:
FAILURE: Build failed with an exception.
- What went wrong: Execution failed for task ':app:compileDebugAidl'.
1 exception was raised by workers: java.lang.RuntimeException: java.lang.RuntimeException: java.io.IOException: com.android.ide.common.process.ProcessException: Error while executing process /Users/boober/Library/Android/sdk/build-tools/28.0.3/aidl with arguments {-p/Users/boober/Library/Android/sdk/platforms/android-29/framework.aidl -o/Users/boober/Desktop/SCRAP/TTSGraft/app/build/generated/aidl_source_output_dir/debug/out -I/Users/boober/Desktop/SCRAP/TTSGraft/app/src/main/aidl -I/Users/boober/Desktop/SCRAP/TTSGraft/app/src/debug/aidl -I/Users/boober/.gradle/caches/transforms-2/files-2.1/1cd7eff88f5e86d0249af2958bf465f0/core-1.1.0/aidl -I/Users/boober/.gradle/caches/transforms-2/files-2.1/929ec10604c047a76453df3294ada6ae/versionedparcelable-1.1.0/aidl -d/var/folders/vz/d68y33c14pjc9m2vrkqp2kvc0000gn/T/aidl4956045951058849495.d /Users/boober/Desktop/SCRAP/TTSGraft/app/src/main/aidl/com/booberbunz/ttsgraft/ITextToSpeechService.aidl}
... and it still would not resolve within MyTextToSpeech.java.
How to get this file into my project locally so that I no longer have the "can't resolve error" in red as seen in image?
And as an aside question: is this actually not possible to do -- to hardcode tts into a project?
Thanks.