Speaker Component - Maple Help

DocumentTools[Components]

 Speaker
 generate XML for a Speaker Component

 Calling Sequence Speaker(opts)

Parameters

 opts - (optional) ; one or more keyword options as described below

Options

 • enabled : truefalse:=true; Indicates whether the component is enabled. The default value is true. If enabled is false, then the inserted component is grayed out and interaction with it cannot be initiated.
 • identity : {name,string}; The reference name of the component.
 • mute : truefalse:=false; Indicates whether the component is initially muted. The default value is false (not muted).
 • samplerate : posint:=16000; The sample rate at which audio data is played. The default value is 16000.
 • stereo : truefalse:=false; Indicates whether audio data is played on two channels (true) or on one channel (false). The default value is false.
 • tooltip : string:=""; The text that appears when the mouse pointer hovers over the component. The default is the empty string (no tooltip).
 • visible : truefalse:=true; Indicates whether the component is visible. The default is true.
 • volume : nonnegint:=5; The volume, an integer between 0 and 10. The default value is 5.

Description

 • The Speaker command in the Component Constructors package returns an XML function call which represents a Speaker Component.
 • The generated XML can be used with the results of commands in the Layout Constructors package to create an entire Worksheet or Document in XML form. Such a representation of a Worksheet or Document can be inserted into the current document using the InsertContent command.

Examples

 > $\mathrm{with}\left(\mathrm{DocumentTools}\right):$
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Components}\right):$
 > $\mathrm{with}\left(\mathrm{DocumentTools}:-\mathrm{Layout}\right):$

Executing the Speaker command produces a function call.

 > $S≔\mathrm{Speaker}\left(\mathrm{identity}="Speaker0"\right)$
 ${S}{≔}{\mathrm{_XML_EC-Speaker}}{}\left({"id"}{=}{"Speaker0"}{,}{"enabled"}{=}{"true"}{,}{"visible"}{=}{"true"}{,}{"samplerate"}{=}{"16000"}{,}{"stereo"}{=}{"false"}{,}{"volume"}{=}{"5"}{,}{"mute"}{=}{"false"}\right)$ (1)

By using commands from the Layout Constructors package a nested function call can be produced which represents a worksheet.

 > $\mathrm{xml}≔\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(S\right)\right)\right)\right):$

That XML representation of a worksheet can be inserted directly.

 > $\mathrm{InsertContent}\left(\mathrm{xml}\right):$

 > $S≔\mathrm{Speaker}\left(\mathrm{identity}="Speaker0",\mathrm{tooltip}="My speaker",\mathrm{stereo}=\mathrm{false}\right):$
 > $\mathrm{xml}≔\mathrm{Worksheet}\left(\mathrm{Group}\left(\mathrm{Input}\left(\mathrm{Textfield}\left(S\right)\right)\right)\right):$

The previous example's call to the InsertContent command inserted a component with identity "Speaker0", which still exists in this worksheet. Inserting additional content whose input contains another component with that same identity "Speaker0" incurs a substitution of the input identity in order to avoid a conflict with the identity of the existing component.

The return value of the following call to InsertContent is a table which can be used to reference the substituted identity of the inserted component.

 > $\mathrm{lookup}≔\mathrm{InsertContent}\left(\mathrm{xml},\mathrm{output}=\mathrm{table}\right)$
 ${\mathrm{lookup}}{≔}{table}{}\left(\left[{"Speaker0"}{=}{"Speaker1"}\right]\right)$ (2)

 > $\mathrm{lookup}\left["Speaker0"\right]$
 ${"Speaker1"}$ (3)
 > $\mathrm{GetProperty}\left(\mathrm{lookup}\left["Speaker0"\right],\mathrm{stereo}\right)$
 ${\mathrm{false}}$ (4)

For the next example, an audio clip is read in, and its data is stored in an Array. This data Array is then sent to the speaker component.

 > $\mathrm{data}≔\mathrm{AudioTools}:-\mathrm{Read}\left(\mathrm{cat}\left(\mathrm{kernelopts}\left(\mathrm{datadir}\right),"/audio/MapleSimMono11025.wav"\right)\right)$
 ${\mathrm{data}}{≔}\left[\begin{array}{cc}{"Sample Rate"}& {11025}\\ {"File Format"}& {\mathrm{PCM}}\\ {"File Bit Depth"}& {16}\\ {"Channels"}& {1}\\ {"Samples/Channel"}& {49664}\\ {"Duration"}& {4.50467}{}{s}\end{array}\right]$ (5)

The speaker component can play audio data at an arbitrary sample rate. The sound clip being used contains its own intended sample rate. The sample rate is the first attribute of the data Array created by the AudioTools:-Read command.

 > $\mathrm{srate}≔\mathrm{attributes}\left(\mathrm{data}\right)\left[1\right]$
 ${\mathrm{srate}}{≔}{11025}$ (6)

The speaker component's sample rate is set accordingly.

 > $\mathrm{SetProperty}\left(\mathrm{lookup}\left["Speaker0"\right],\mathrm{samplerate},\mathrm{srate}\right)$

The data is now sent to the Speaker component, playing the audio clip.

 > $\mathrm{SetProperty}\left(\mathrm{lookup}\left["Speaker0"\right],\mathrm{value},\mathrm{data}\right)$
 > 

Compatibility

 • The DocumentTools:-Components:-Speaker command was introduced in Maple 2015.