Skip to main content

speakText()

Converts text to speech using Android’s Text-to-Speech (TTS) engine. This is the primary method for providing voice feedback during automation.
text
string
required
The text to speak. Supports plain text only.
return
void
This function does not return a value.

Basic Usage

// Speak a simple message
Android.speakText("Hello, world!");

// Provide status updates
Android.speakText("Starting automation workflow");

// Announce errors
Android.speakText("Error: Unable to find element");

Practical Examples

// Automation progress feedback
Android.speakText("Opening Instagram");
Android.delay(2000);

Android.speakText("Logging in");
Android.delay(3000);

Android.speakText("Login successful");

Implementation Details

Source Location

MainActivity.kt:4936
@JavascriptInterface
fun speakText(text: String) {
    this@MainActivity.speakText(text)
}

TTS Engine

The function uses Android’s built-in TextToSpeech service, which:
  • Initializes on app startup
  • Supports multiple languages (based on device settings)
  • Queues messages if multiple calls are made rapidly
  • Requires TextToSpeech.OnInitListener callback
Speech synthesis is asynchronous. The function returns immediately while the device speaks in the background.

Best Practices

Short messages (under 10 words) are easier to understand and don’t delay automation flow.
// Good
Android.speakText("Task complete");

// Avoid
Android.speakText("The automated task has successfully completed execution and all steps have been performed without any errors occurring during the process");
If critical timing is needed, add a delay after speakText() to ensure the message completes.
Android.speakText("Please wait");
Android.delay(1500); // Wait for speech to finish
Speech is invaluable for debugging automations on remote devices where you can’t see the screen.
Android.speakText("Checkpoint 1 reached");
// ... automation code ...
Android.speakText("Checkpoint 2 reached");

Common Use Cases

Workflow Status

Announce each step of a multi-step automation:
Android.speakText("Starting login flow");
Android.simulateTypeInFirstEditableField("user@example.com");

Android.speakText("Entering password");
Android.simulateTypeInSecondEditableField("password123");

Android.speakText("Submitting form");
Android.pressEnterKey();

Debug Mode

Provide verbose feedback during development:
const DEBUG = true;

function debugLog(message) {
  if (DEBUG) {
    Android.speakText("Debug: " + message);
  }
}

debugLog("Starting automation");
Android.simulateClick(100, 200);
debugLog("Click performed");

User Notifications

Alert users to important events:
const newMessages = 3;
if (newMessages > 0) {
  Android.speakText("You have " + newMessages + " new messages");
}

Limitations

  • Speech language depends on device TTS engine settings
  • Some devices may not have TTS engines installed
  • Speech output may be muted if device volume is low
  • Multiple rapid calls queue up rather than interrupting