Namespace mmir.MediaManager
Defined in: mediaManager.js.
Constructor Attributes | Constructor Name and Description |
---|---|
The MediaManager gives access to audio in- and output functionality.
|
Field Attributes | Field Name and Description |
---|---|
A logger for the MediaManager and its plugins/modules.
|
|
Execution context for plugins
TODO add doc
|
|
Wait indicator, e.g.
|
Method Attributes | Method Name and Description |
---|---|
addListener(eventName, eventHandler)
Adds the handler-function for the event.
|
|
cancelRecognition(successCallBack, failureCallBack)
Cancel currently active speech recognition.
|
|
cancelSpeech(successCallBack, failureCallBack)
Cancel current synthesis.
|
|
Get an empty audio object.
|
|
getFunc(ctx, funcName)
Returns function
funcName from "sub-module" ctx . |
|
getListeners(eventName)
Get list of registered listeners / handlers for an event.
|
|
getURLAsAudio(url, onPlayedCallback, failureCallBack, onLoadedCallBack)
Get an audio object for the audio file specified by URL.
|
|
hasListeners(eventName)
Check if at least one listener / handler is registered for the event.
|
|
Same as #init.
|
|
MediaManager#init(successCallback, failureCallback, listenerList)
Object containing the instance of the class {{#crossLink "audioInput"}}{{/crossLink}}
If listenerList is provided, each listener will be registered after the instance
is initialized, but before media-plugins (i.e.
|
|
MediaManager#loadFile(filePath, successCallback, failureCallback, execId)
loads a file.
|
|
off()
|
|
on()
|
|
perform(ctx, funcName, args)
Executes function
funcName in "sub-module" ctx
with arguments args . |
|
playURL(url, onPlayedCallback, failureCallBack)
Play audio file from the specified URL.
|
|
playWAV(blob, onPlayedCallback, failureCallBack)
Play PCM audio data.
|
|
recognize(successCallBack, failureCallBack)
Start speech recognition with end-of-speech detection:
the recognizer automatically tries to detect when speech has finished and then
triggers the callback with the result.
|
|
removeListener(eventName, eventHandler)
Removes the handler-function for the event.
|
|
setDefaultCtx(ctxId)
Set the default execution context.
|
|
setTextToSpeechVolume(newValue)
Set the volume for the speech synthesis (text-to-speech).
|
|
startRecord(successCallBack, failureCallBack, isWithIntermediateResults)
Start continuous speech recognition:
The recognizer continues until #stopRecord is called.
|
|
stopRecord(successCallBack, failureCallBack)
Stops continuous speech recognition:
After #startRecord was called, invoking this function will stop the recognition
process and return the result by invoking the
succesCallback . |
|
textToSpeech(parameter, onPlayedCallback, failureCallBack)
Synthesizes ("read out loud") text.
|
mmirf/env/media
for available plugins.
This "class" is a singleton - so that only one instance is in use.- Requires:
- jQuery.extend
- jQuery.Deferred TODO remove / change dependency on forBrowser: constants.isBrowserEnv()!!!
This logger MAY be used by media-plugins and / or tools and helpers related to the MediaManager.
This logger SHOULD NOT be used by "code" that non-related to the MediaManager
- Default Value:
- mmir.Logger (logger instance for mmir.MediaManager)
- Default Value:
- Object (empty context, i.e. plugins are loaded into the "root context", and no plugins loaded into the execution context)
provides 2 functions:
preparing()
: if called, the implementation indicates that the "user should wait"
ready()
: if called, the implementation stops indicating that the "user should wait" (i.e. that the system is ready for user input now)
If not set (or functions are not available) will do nothing
//define custom wait/ready implementation: var impl = { preparing: function(str){ console.log('Media module '+str+' is preparing...'); }, ready: function(str){ console.log('Media module '+str+' is ready now!'); } }; //configure MediaManager to use custom implementation: mmir.MediaManager.waitReadyImpl = impl; //-> now plugins that call mmir.MediaManager._preparing() and mmir.MediaManager._ready() // will invoke the custom implementation's functions.
- See:
- #_preparing
- #_ready
- Default Value:
- Object (no implementation set)
actionType "added"
.
Event names (and firing events) are specific to the loaded media plugins.
TODO list events that the default media-plugins support
* "miclevelchanged": fired by AudioInput plugins that support querying the microphone (audio input) levels
A plugin can tigger / fire events using the helper #_fireEvent
of the MediaManager.
Media plugins may observe registration / removal of listeners
via #_addListenerObserver and #_removeListenerObserver.
Or get and iterate over listeners via #getListeners.
- Parameters:
- {String} eventName
- {Function} eventHandler
- Parameters:
- successCallBack
- failureCallBack
- Parameters:
- successCallBack
- failureCallBack
play() stop() release() enable() disable() setVolume(number) getDuration() isPaused() isEnabled()Note:
enable()
and disable()
will set the internal
enabled-state, which can be queried via isEnabled()
.
play()
and stop()
will set the internal
playing-state, which can be queried via isPaused()
(note however, that this empty audio does not actually play anything.
setVolume()
sets the internal volume-value.
getDuration()
will always return 0
.
- Returns:
- {mmir.env.media.IAudio} the audio
- See:
funcName
from "sub-module" ctx
.
If there is no funcName
in "sub-module" ctx
,
then funcName
from the "main-module" (i.e. from the MediaManager
instance itself) will be returned.
NOTE that the returned functions will always execute within the context of the
MediaManager instance (i.e. this
will refer to the MediaManager instance).
//same as mmir.MediaManager.ctx.android.textToSpeech("...", function...): mmir.MediaManager.getFunc("android", "textToSpeech")("some text to read out loud", function onFinished(){ console.log("finished reading."); } ); //same as mmir.MediaManager.textToSpeech("...", function...): //... IF the defaultExecId is falsy // (i.e. un-changed or set to falsy value via setDefaultExec()) mmir.MediaManager.getFunc(null, "textToSpeech")("some text to read out loud", function onFinished(){ console.log("finished reading."); } );
- Parameters:
- {String} ctx
- the execution context, i.e. "sub-module", in which to execute funcName.
Iffalsy
, the "root-module" will used as execution context. - {String} funcName
- the function name
- Throws:
- {ReferenceError}
- if
funcName
does not exist in the requested Execution context.
Or ifctx
is notfalsy
but there is no valid execution contextctx
in MediaManager.
- Parameters:
- eventName
- Returns:
- {Array
} of event-handlers. Empty, if there are no event handlers for eventName
play() stop() release() enable() disable() setVolume(number) getDuration() isPaused() isEnabled()NOTE: the audio object should only be used, after the
onLoadedCallback
was triggered.
- Parameters:
- {String} url
- {Function} onPlayedCallback Optional
- OPTIONAL
- {Function} failureCallBack Optional
- OPTIONAL
- {Function} onLoadedCallBack Optional
- OPTIONAL
- Returns:
- {mmir.env.media.IAudio} the audio
- See:
- Parameters:
- eventName
- Returns:
- {Boolean}
true
if at least 1 handler is registered for eventName; otherwisefalse
.
- Deprecated:
-
access MediaManger directly via
mmir.MediaManager.someFunction
- &tl;internal: for initialization useinit()
instead>
name: is the name of the event
listener: is the listener implementation (the signature/arguments of the listener function depends on the specific event for which the listener will be registered)
- Parameters:
- {Function} successCallback Optional
- OPTIONAL callback that gets triggered after the MediaManager instance has been initialized.
- {Function} failureCallback Optional
- OPTIONAL a failure callback that gets triggered if an error occurs during initialization.
- {Array listenerList Optional
- OPTIONAL
a list of listeners that should be registered, where each entry is an Object
with properties:
{ name: String the event name, listener: Function the handler function }
- Returns:
- {Object} an Deferred object that gets resolved, after the mmir.MediaManager has been initialized.
- Parameters:
- filePath
- successCallback
- failureCallback
- execId
- Deprecated:
- do not use.
- See:
- #removeListener
- See:
- #addListener
funcName
in "sub-module" ctx
with arguments args
.
If there is no funcName
in "sub-module" ctx
,
then funcName
from the "main-module" (i.e. from the MediaManager
instance itself) will be used.
//same as mmir.MediaManager.ctx.android.textToSpeech("...", function...): mmir.MediaManager.perform("android", "textToSpeech", ["some text to read out loud", function onFinished(){ console.log("finished reading."); } ]); //same as mmir.MediaManager.textToSpeech("...", function...) //... IF the defaultExecId is falsy // (i.e. un-changed or set to falsy value via setDefaultExec()) mmir.MediaManager.perform(null, "textToSpeech", ["some text to read out loud", function onFinished(){ console.log("finished reading."); } ]);
- Parameters:
- {String} ctx
- the execution context, i.e. "sub-module", in which to execute funcName.
Iffalsy
, the "root-module" will used as execution context. - {String} funcName
- the function name
- {Array} args
- the arguments for function "packaged" in an array
- Throws:
- {ReferenceError}
- if
funcName
does not exist in the requested Execution context.
Or ifctx
is notfalsy
but there is no valid execution contextctx
in MediaManager.
- Parameters:
- url
- onPlayedCallback
- failureCallBack
- Parameters:
- blob
- onPlayedCallback
- failureCallBack
- Parameters:
- {Function} successCallBack Optional
- OPTIONAL
callback function that is triggered when a text result is available.
The callback signature is:
callback(textResult)
- {Function} failureCallBack Optional
- OPTIONAL
callback function that is triggered when an error occurred.
The callback signature is:
callback(error)
actionType "removed"
, if the handler
was actually removed.
- Parameters:
- {String} eventName
- {Function} eventHandler
- Returns:
- {Boolean}
true
if the handler function was actually removed, andfalse
otherwise.
falsy
value,
then the "root" execution context is the default context.
//if context "nuance" exists: mmir.MediaManager.setDefaultCtx("nuance") // -> now the following calls are equal to mmir.MediaManager.ctx.nuance.textToSpeech("some text") mmir.MediaManager.perform(null, "textToSpeech", ["some text"]); mmir.MediaManager.getFunc(null, "textToSpeech")("some text"); //reset to root context: mmir.MediaManager.setDefaultCtx("nuance"); // -> now the following call is equal to mmir.MediaManager.textToSpeech("some text") again mmir.MediaManager.perform("textToSpeech", ["some text"]);
- Parameters:
- {String} ctxId
- the new default excution context for loaded media modules
(if
falsy
the default context will be the "root context")
- Throws:
- {ReferenceError}
- if
ctxId
is no valid context
- Parameters:
- {Number} newValue
- TODO specify format / range
If isWithIntermediateResults
is used, the recognizer may
invoke the callback with intermediate recognition results.
TODO specify whether stopRecord should return the "gathered" intermediate results, or just the last one
NOTE that not all implementation may support this feature.
- Parameters:
- {Function} successCallBack Optional
- OPTIONAL
callback function that is triggered when a text result is available.
The callback signature is:
callback(textResult)
- {Function} failureCallBack Optional
- OPTIONAL
callback function that is triggered when an error occurred.
The callback signature is:
callback(error)
- {Boolean} isWithIntermediateResults Optional
- OPTIONAL
if
true
, the recognizer will return intermediate results by invoking the successCallback
- See:
- #stopRecord
succesCallback
.
TODO specify whether stopRecord should return the "gathered" intermediate results, or just the last one
- Parameters:
- {Function} successCallBack Optional
- OPTIONAL
callback function that is triggered when a text result is available.
The callback signature is:
callback(textResult)
- {Function} failureCallBack Optional
- OPTIONAL
callback function that is triggered when an error occurred.
The callback signature is:
callback(error)
- See:
- #startRecord
- Parameters:
-
{String|Array
|PlainObject} parameter - if
String
orArray
ofString
s synthesizes the text of the String, for an Array: each entry is interpreted as "sentence"; after each sentence, a short pause is inserted before synthesizing the the next sentence
for aPlainObject
, the following properties should be used:{ text: string OR string Array, text that should be read aloud , pauseLength: OPTIONAL Length of the pauses between sentences in milliseconds , forceSingleSentence: OPTIONAL boolean, if true, a string Array will be turned into a single string , split: OPTIONAL boolean, if true and the text is a single string, it will be split using a splitter function , splitter: OPTIONAL function, replaces the default splitter-function. It takes a simple string as input and gives a string Array as output }
- onPlayedCallback
- failureCallBack