pebble
  • Tutorials
  • Get the SDK
  • Guides
  • Documentation
  • PebbleOS
  • Mobile App
  • Examples
  • Index 01
  • Community
  • Blog
  • More
Privacy
Cookies
Publish

Pebble C API

  • Pebble C API
  • Moddable API (Alloy)
  • PebbleKit JS
  • PebbleKit iOS
  • PebbleKit Android
  • Foundation
    • Alloy
    • App
    • App Communication
    • App Glance
    • AppMessage
    • AppSync
    • AppWorker
    • DataLogging
    • DataStructures
      • UUID
    • Dictation
    • Dictionary
    • Event Service
      • AccelerometerService
      • AlarmService
      • AppFocusService
      • BacklightService
      • BatteryStateService
      • CompassService
      • ConnectionService
      • HealthService
      • TickTimerService
      • TouchService
    • Exit Reason
    • Internationalization
    • Launch Reason
    • Logging
    • Math
    • Memory Management
    • Platform
    • Resources
      • File Formats
    • Storage
    • Timer
    • Wakeup
    • Wall Time
    • WatchInfo
  • Graphics
    • Draw Commands
    • Drawing Paths
    • Drawing Primitives
    • Drawing Text
    • Fonts
    • Graphics Context
    • Graphics Types
      • Color Definitions
  • User Interface
    • Animation
      • PropertyAnimation
    • Clicks
    • Gesture Recognizers
    • Layers
      • ActionBarLayer
      • BitmapLayer
      • MenuLayer
      • RotBitmapLayer
      • ScrollLayer
      • SimpleMenuLayer
      • StatusBarLayer
      • TextLayer
    • Light
    • Microphone
    • Preferences
    • Speaker
    • UnobstructedArea
    • Vibes
    • Window
      • ActionMenu
      • NumberWindow
    • Window Stack
  • Worker
  • Standard C
    • Format
    • Locale
    • Math
    • Memory
    • String
    • Time

The APIs on this page will only work with SDK 4.9+.

Microphone

Function Documentation

MicStreamStartResult mic_stream_to_phone_start(MicStreamHandlers handlers, void * context)

Starts streaming the microphone to the app's PebbleKit JS companion.

Parameters

handlers

stopped is required

context

Passed to the handlers

void mic_stream_to_phone_stop(void)

Stops streaming. Safe to call when not streaming.

bool mic_stream_to_phone_is_active(void)

Returns

true while the app is streaming to the phone, including while the phone has yet to accept the stream

MicCaptureStartResult mic_capture_start(MicCaptureHandlers handlers, void * context)

Both handlers are required. Capture starts immediately on success.

void mic_capture_stop(void)

Stops capture without calling stopped. Safe while idle.

bool mic_capture_is_active(void)
bool layer_get_mic_accessory_bounds(const Layer * layer, GRect * bounds_out)

Get the area next to the system Listening indicator, for the app's own content while it uses the microphone. On rectangular displays the indicator is a bar along the bottom of the screen that shrinks into a square in the bottom-left corner after a few seconds. The bar's height stays obstructed (see layer_get_unobstructed_bounds) and this is the rest of it, to the right of the square: a place for a timer, a level meter or a hint.

Draw in it whenever this returns true. The bar covers it at first and uncovers it as it shrinks, so there is nothing to time. It keeps the bar's height while the indicator slides in and out, so what is drawn in it moves with the indicator. The app redraws whenever it moves, as for the unobstructed area.

It is true from when the app starts using the microphone until the indicator has slid away. On round displays the indicator is a small dome that leaves no room, so this is always false: show that content in the unobstructed area instead.

Parameters

layer

The layer for which to get the area, in its coordinates. The area is clipped to the layer's sides, but not to its top or bottom.

bounds_out

The area, or an empty rectangle when there is none.

Returns

false when the app is not using the microphone, on round displays and when the area is beside the layer.

See Also

UnobstructedArea

Data Structure Documentation

struct MicCaptureHandlers

Data Fields

MicCaptureDataHandler data
MicCaptureStoppedHandler stopped
struct MicStreamHandlers

Data Fields

MicStreamStartedHandler started
MicStreamStoppedHandler stopped

Enum Documentation

enum MicStreamStartResult

Result of mic_stream_to_phone_start.

Enumerators

MicStreamStartOk

The stream was requested; started is called once the phone accepts it.

MicStreamStartErrBusy

The microphone is in use (by this app or the system)

MicStreamStartErrNotForeground

The app is not in the foreground.

MicStreamStartErrInvalidArgs

Invalid arguments.

MicStreamStartErrNoMemory

Not enough memory to start the stream.

MicStreamStartErrWatchface

Watchfaces can never stream.

MicStreamStartErrUnavailable

This watch has no microphone.

enum MicStreamStopReason

Why the stream ended.

Enumerators

MicStreamStopReasonStopped

The app stopped the stream.

MicStreamStopReasonFocusLost

The app lost focus, e.g. a notification appeared.

MicStreamStopReasonInterrupted

The system took the microphone, e.g. for dictation.

MicStreamStopReasonPhone

The phone refused, stopped or lost the stream.

MicStreamStopReasonError

An unexpected error.

enum MicCaptureStartResult

Enumerators

MicCaptureStartOk
MicCaptureStartErrBusy
MicCaptureStartErrNotForeground
MicCaptureStartErrInvalidArgs
MicCaptureStartErrWatchface
MicCaptureStartErrUnavailable
MicCaptureStartErrPermissionDenied
MicCaptureStartErrNoMemory
enum MicCaptureStopReason

Enumerators

MicCaptureStopReasonFocusLost
MicCaptureStopReasonInterrupted
MicCaptureStopReasonPermissionRevoked

Typedef Documentation

typedef void(* MicStreamStartedHandler)(void *context)

Handler called once the phone has accepted the stream and audio is flowing.

typedef void(* MicStreamStoppedHandler)(MicStreamStopReason reason, void *context)

Handler called when the stream ends for a reason other than the app stopping it. The stream is gone by the time it is called.

typedef void(* MicCaptureDataHandler)(const int16_t *samples, size_t sample_count, void *context)

Runs on the app task. Samples are valid only during this callback. Slow consumers drop frames; each callback receives 320 samples (20 ms).

typedef void(* MicCaptureStoppedHandler)(MicCaptureStopReason reason, void *context)

Called on the app task when capture ends involuntarily.

Macro Definition Documentation

#define MIC_CAPTURE_SAMPLE_RATE 16000

Local 16 kHz mono signed 16-bit PCM capture. Requires an explicit Microphone grant synced from the phone. Grants persist offline until updated by the phone. Only foreground watchapps can capture. The system displays its Listening banner (see layer_get_mic_accessory_bounds). Capture and mic_stream_to_phone_start cannot run at the same time.

Need some help?

Functions

  • mic_stream_to_phone_start
  • mic_stream_to_phone_stop
  • mic_stream_to_phone_is_active
  • mic_capture_start
  • mic_capture_stop
  • mic_capture_is_active
  • layer_get_mic_accessory_bounds

Data Structures

  • MicCaptureHandlers
  • MicStreamHandlers

Enums

  • MicStreamStartResult
  • MicStreamStopReason
  • MicCaptureStartResult
  • MicCaptureStopReason

Typedefs

  • MicStreamStartedHandler
  • MicStreamStoppedHandler
  • MicCaptureDataHandler
  • MicCaptureStoppedHandler

Macro Defintions

  • MIC_CAPTURE_SAMPLE_RATE

Getting Help

Do you have questions about the Pebble SDK?

Do you need some help understanding something on this page?

Ask on the developer forum.