Segment SDK package

segment

No package description available.

Summary

Type definitions
oncommand Callback to notify the segment of a voice command.
onpause Callback to pause a segment
onpreprocess Callback to prepare a segment for play
onresume Callback to resume a paused segment
onstart Callback to start a segment or a worker
onstop Callback to stop a segment

Type definitions

oncommand(commandObject)

Type
function

Callback to notify the segment of a voice command.

Parameters
Name Type Description
commandObject object

Properties
Name Type Description
command string Voice command
  • next:move to next topic.
  • previous:move to the previous topic.
  • again:repeat the current topic.
  • detail:get detail of the current topic.
  • bookmark:save the current topic as a bookmark.

Returns
Type Description
boolean Consumed
When the input command is used, true is returned. If not, return false.

onpause()

Type
function

Callback to pause a segment. System mutes the segment playback when calling this method.

This method is called by the system when:

  • a user starts a voice command
  • a system interruption occurs, such as notifications.
You should use onpause() callback to manage and suspend the segment process for segment.onresume callback.
Usually you use this callback to:
  • save playback condition of the segment to continue when onresume is triggered afterwards.
  • prevent TTS from playing while the segment is paused

onpreprocess(trigger, args)

Type
function

Callback to prepare a segment for play.

It can take time to prepare your segment for play, due to the preparation of TTS and fetching data from relevant service.
The preparation of a segment should usually contain:

  • fetching the relevant data from the server.
  • checking the conditions that triggered the segment.
Your implementation of segment.onpreprocess should check the conditions that triggered the segment and either call da.startSegment method or da.cancelSegment method.
Once the da.startSegment is called by your segment, the Personalized Radio function initializes speech of segment and play back the bumper sound and loop the playpack.

Parameters
Name Type Description
trigger string The trigger type of a segment
  • voice: to launch a segment by a voice command.
  • launchRule: to launch a segment by the rules defined in LaunchRule.json.
  • worker: to launch a segment by a worker
args object The input arguments from the framework that corresponding to different trigger types.
  • an object of voice recognition, when the trigger is 'voice'.
  • a set of objects that are created from LaunchRule.json, when the trigger is 'launchRule'.
  • a set of objects of argumentObject.args that are passed from a worker, when the trigger is 'Worker'.

onresume()

Type
function

Callback to resume a paused segment.

This method is usually called after segment.onpause callback when:

  • the voice recognition has finished.
  • the interruption process has finished.

You should usually use this method to:
  • restore playback condition of the segment that were saved by onpause() method.

onstart(trigger, args)

Type
function

Callback to start a segment or a worker

Parameters
Name Type Description
trigger string The trigger type of a segment. It can be 'voice', 'launchRule', 'worker', or null in a worker's onstart callback method.
args object Args to start the segment; or null to use the default value in a segment's onstart callback method. The default value is null in a worker's onstart callback method.

onstop()

Type
function

Callback to stop a segment.

You usually should use this method to:

  • Save information and its ID to the server or storage.

■Note:
  • Do not implement a process that waits for asynchronous responses.
    It is possible that such a process is discontinued, as the segment ends without waiting for the response.