pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • Examples
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Guides

  • Table of Contents
  • Alloy
    • Getting Started with Alloy
    • Piu UI Framework
    • Poco Graphics
    • Sensors and Input
    • Storage
    • Networking
    • App Messages
    • Watchfaces
    • Animations
    • Port (Custom Drawing)
    • Advanced Networking
    • Native Functions (FFI)
    • Dictation
    • Wakeups
    • Vibration
    • Device Info and App Events
  • App Resources
  • Best Practices
  • Communication
  • Debugging
  • Design and Interaction
  • Events and Services
  • Graphics and Animations
  • Pebble Packages
  • Pebble Timeline
  • Tools and Resources
  • User Interfaces

Dictation

The Dictation class lets your Alloy app capture speech from the user and receive it as text. It drives the system dictation UI and delivers the transcription to your code through callbacks.

Platform Support: Dictation is available on Emery (Pebble Time 2) and Gabbro (Pebble Time 2 round), and requires a connected phone with a working internet connection.

Basic Usage

Import the class and create an instance with onReadable and onError handlers, then call start() to begin listening:

import Dictation from "pebble/dictation";

let dictation = new Dictation({
    onReadable() {
        console.log(`Transcription: ${this.read()}`);
    },
    onError(e) {
        console.log(`Dictation error: ${e}`);
    }
});

dictation.start();

Methods

Method Description
start() Open the dictation UI and begin listening.
stop() Stop an in-progress dictation session.
read() Return the transcribed text. Call from onReadable.
configure(options) Change dictation behavior (see Configuration).
close() Release the dictation instance when you're done with it.

Events

Event Description
onReadable() Called when a transcription is ready. Call this.read() to get the text.
onError(status) Called when dictation fails (for example, no connection or no speech detected). status is a numeric error code.

Configuration

Pass a byteLength to the constructor to size the transcription buffer, and use configure() to control the dictation UI:

import Dictation from "pebble/dictation";

let dictation = new Dictation({
    byteLength: 512,   // maximum transcription size, in bytes
    onReadable() {
        console.log(`Transcription: ${this.read()}`);
    }
});

dictation.configure({
    confirm: false,       // skip the confirmation screen after dictation
    errorDialogs: true    // let the system show its own error dialogs
});

dictation.start();
Option Description
confirm Whether to show the confirmation screen after dictation (default true).
errorDialogs Whether the system shows its own error UI on failure.

Continuous Dictation

To keep listening after each transcription, start a new session from within onReadable. Use setImmediate so the current session finishes cleanly first:

import Dictation from "pebble/dictation";

let dictation = new Dictation({
    onReadable() {
        console.log(`Transcription: ${this.read()}`);
        setImmediate(() => {
            console.log("Listening...");
            this.start();
        });
    },
    onError(e) {
        console.log(`Dictation error: ${e}`);
    }
});

console.log("Listening...");
dictation.start();

See the hellodictation example for a complete project.

You need JavaScript enabled to read and post comments.

Overview

  • Basic Usage
  • Methods
  • Events
  • Configuration
  • Continuous Dictation