Voice

This service handles voice control endpoint messages, parses the data and exposes it for external tools. It also allows voice control messages to be sent to a Pebble. It does not implement the state machine for ordering voice control messages correctly: this must be handled by the user of the service.

Events

The service exposes the following events, which can be subscribed to with VoiceServer.register_handler:

  • session_setup - Session setup request received
  • audio_frame - Audio data frame received
  • audio_stop - Audio data stopped

Voice Protocol Sequencing

The correct sequencing for communicating with the Pebble smartwatch is as follows:

Pebble-terminated sessions:

This is the normal sequence of communication. The Server should wait until it receives a stop message from the Pebble before sending the dictation result.

Message Sender Event/Function
Session setup request Pebble session_setup
Session setup result Server VoiceService.send_session_setup_result
Audio data (n frames) Pebble audio_frame
Audio stop Pebble audio_stop
Dictation result Server VoiceService.send_dictation_result

Server-terminated sessions:

If an error occurs a server can terminate the session by sending an audio stop message followed by the dictation result. The dictation result should always be sent.

Message Sender Event/Function
Session setup request Pebble session_setup
Session setup result Server VoiceService.send_session_setup_result
Audio data (n frames) Pebble audio_frame
Audio stop Server VoiceService.send_stop_audio
Dictation result Server VoiceService.send_dictation_result
class libpebble2.services.voice.VoiceService(pebble)

Service to expose voice control to external tools

Parameters:pebble (PebbleConnection) – The pebble with which to establish a voice session.
SESSION_ID_INVALID = 0
register_handler(event, handler)

Registers a handler to be triggered by an event

Parameters:
  • event – The event to handle
  • handler – The handler callable.
Returns:

A handle that can be used to unregister the handler.

send_dictation_result(result, sentences=None, app_uuid=None)

Send the result of a dictation session

Parameters:
  • result (DictationResult) – Result of the session
  • sentences – list of sentences, each of which is a list of words and punctuation
  • app_uuid (uuid.UUID) – UUID of app that initiated the session
send_session_setup_result(result, app_uuid=None)

Send the result of setting up a dictation session requested by the watch

Parameters:
  • result (SetupResult) – result of setting up the session
  • app_uuid (uuid.UUID) – UUID of app that initiated the session
send_stop_audio()

Stop an audio streaming session

unregister_handler(handle)

Unregisters an event handler.

Parameters:handle – The handle returned from register_handler()
wait_for_event(event, timeout=10)

Block waiting for the given event. Returns the event params.

Parameters:
  • event – The event to handle.
  • timeout – The maximum time to wait before raising TimeoutError.
Returns:

The event params.

class libpebble2.services.voice.SetupResult
FailDisabled = <SetupResult.FailDisabled: 5>
FailTimeout = <SetupResult.FailTimeout: 2>
Success = <SetupResult.Success: 0>
class libpebble2.services.voice.TranscriptionResult
FailNoInternet = <TranscriptionResult.FailNoInternet: 1>
FailRecognizerError = <TranscriptionResult.FailRecognizerError: 3>
FailSpeechNotRecognized = <TranscriptionResult.FailSpeechNotRecognized: 4>
Success = <TranscriptionResult.Success: 0>