STMediaRunner Module (SDK Reference)
| Declared in | STMediaRunner.swift |
Overview
STMediaRunner class provides the methods which allow an application to execute lower level media tasks such as:
- Audio Playback
- Audio Recording
- Speech Synthesis
- Speech Recognition on device and file audio
- Voice activity detection on recorded audio
- Application audio session configuration
- Real time media event detection and application notification
- Multi-level logging
- Granular application control over all media tasks execution
and more.
Internally in STVoiceFlow framework, STVoiceFlowRunner module utilizes the methods provided by STMediaRunner module in order to execute configurable and runtime adaptable speech-enabled interactions between an application and its users. Methods exposed by STMediaRunner module are also available to application developers should the developers have a need to execute these methods directly.
A STMediaRunner object is a a shared object that is created internally in STMediaRunner module. It is accessed as follows::
let mediaRunner = STMediaRunner.shared
Example:
#import STVoiceFlow
public final class MyMediaRunner: STEventsObserverDelegate {
let mediaRunner = STMediaRunner.shared
var eventsObserver: STEventsObserver? = nil
let logLevels:[String:String?] = [
"MediaPermissions":"debug",
"AudioFilePlayer":"debug",
"AudioFileRecorder":"debug",
"AudioSession":"debug",
"AudioPlayer":"debug",
"AudioRecorder":"debug",
"AppleSS":"debug",
"AppleSR":"error",
]
func initializeMediaRunner () {
eventsObserver = STEventsObserver()
eventsObserver!.delegate = self
mediaRunner.setLogLevel("debug"")
mediaRunner.setModulesLogLevels(logLevels)
var result:ST_RESULT = mediaRunner.initialize()
#if !os(macOS)
var stAudioSessionParams = STAudioSessionParams()
let value1 = Int(STAudioSessionCategoryOption.ASCO_AllowBluetooth.rawValue | STAudioSessionCategoryOption.ASCO_DuckOthers.rawValue | STAudioSessionCategoryOption.ASCO_DefaultToSpeaker.rawValue)
stAudioSessionParams.audioSessionCategoryOption = value1
stAudioSessionParams.audioSessionMode = STAudioSessionMode.ASM_Default
result = mediaRunner.configureAudioSession(stAudioSessionParams)
#endif
result = mediaRunner.requestMicrophonePermission()
if result == .ST_PERMISSION_GRANTED {
} else { }
result = mediaRunner.requestSpeechRecognitionPermission()
if result == .ST_PERMISSION_GRANTED {
} else { }
}
// Optional implementation of media event notification from STMediaRunner module using STEventsObserverDelegate protocol
func STMedia_EventNotification(_ mediaJobID: String!, mediaItemID: String!, mediaFunction: STNotifyMediaFunction, mediaEvent: STNotifyMediaEvent, mediaEventData: [AnyHashable : Any]!) {
}
}
Tasks
-
– setLogLevelSets the log level of the
STMediaRunnermedia module. Usually, this method is invoked before initializing theSTMediaRunnershared object.
On Apple devices Unified logging is utilized. All logs are available in Apple’s Console application. Also all logs are visible in Xcode output console when running the application in Xcode in debug mode.
The following are the valid log levels:
- “none”
- “fault”
- “error”
- “default”
- “info”
- “debug”
- “verbose”
Default log level is: “default”.
Sample implementation code: -
– setComponentsLogLevelsSets the log levels of the
STMediaRunnermodule components. Usually, this method is invoked before initializing theSTMediaRunnershared object.STMediaRunnermodule contains many media components. Logging for each media component can be controlled independently.
On Apple devices Unified logging is utilized. All logs are available in Apple’s Console application. Also all logs are visible in Xcode output console when running the application in Xcode in debug mode.
Here is a list of the media components forSTMediaRunnermodule:
- “MediaRunner”
- “MediaPermissions”
- “AudioSession”
- “AudioPlayer”
- “AudioFilePlayer”
- “AudioRecorder”
- “AudioFileRecorder”
- “AppleSS”
- “AppleSR”
The following are the valid log levels:
- “none”
- “fault”
- “error”
- “default”
- “info”
- “debug”
- “verbose”
Default log level for all media components is: “default”.
Sample implementation code: -
– getComponentLogLevelRetrieves the logging level for one of the
STMediaRunnermodule components.
Media components ofSTMediaRunnermodule have the following types: “MediaRunner”, “MediaPermissions”, “AudioSession”, “AudioRecorder”, “AudioFileRecorder”, “AudioPlayer”, “AudioFilePlayer”, “AppleSR” and “AppleSS”.
Log level is a string value and is set to one of the following values: “none”, “fault”, “error”, “default”, “info”, “debug” and “verbose”. -
– initializeInitializes the
STMediaRunnermodule. This method must be called to set up all the media components and to enable media procesing using these components. Some of theSTMediaRunnermodule components must also be initialized using their respective initilization methods after this method is called.
Sample implementation code: -
– initializeAudioPlayerInitializes the audio player media component of the media module. This method must be called before calling other methods that require functionlity such as audio playback.
Method returns a ST_RESULT value. -
– releaseAudioPlayerReleases the audio player media component.
Method returns a ST_RESULT value. -
– configureAudioSessionConfigures the audio session created by the
STMediaRunnermodule. -
– routeDeviceAudioOutputRoutes audio playback to a specific audio output destination on a device. Example is to route audio to a device internal speaker or to the device external speaker.
Method returns a ST_RESULT value. -
– playAudioProvides audio playback of an audio segment. Audio segment can be a recorded audio file or real-time synthesized speech provided by a speech synthesizer for text. This method executes asynchronously when the method returns
ST_SUCCESS.
STMediaRunnermodule sends real time event notifications about status of audio playback to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value. -
– stopAudioPlaybackInstructs
STMediaRunnermodule to stop audio playback before audio playback completes. This method executes asynchronously when the method returnsST_SUCCESS.
STMediaRunnermodule sends real time event notifications about status of audio playback to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value. -
– pauseAudioPlaybackInstructs
STMediaRunnermodule to pause audio playback. This method executes asynchronously when the method returnsST_SUCCESS.
STMediaRunnermodule sends real time event notifications about status of audio playback to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value. -
– resumeAudioPlaybackInstructs
STMediaRunnermodule to resume audio playback. This method executes asynchronously when the method returnsST_SUCCESS.
STMediaRunnermodule sends real time event notifications about status of audio playback to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value. -
– resetAudioPlaybackParamsInstructs
STMediaRunnermodule to reset audio playback parameters before next audio playback.
-
– setAudioPlaybackVolumeInstructs
STMediaRunnermodule to change the audio playback volume. Valid values of volume are between 0.0 and 1.0. Defautlt value is 1.0 which is full volume..
Method returns a ST_RESULT value. -
– setAudioPlaybackPitchInstructs
STMediaRunnermodule to change the audio playback pitch. Valid values of rate are between -2.0 and 2.0. Defautlt value is 0.0 which is normal pitch. Each 1.0 interval represnts one octave. each octave is 1200 cents. One musical semitone is equal to 100 cents. So each semitome is a value of 0.0833.
Method returns a ST_RESULT value. -
– setAudioPlaybackRateInstructs
STMediaRunnermodule to change the audio playback rate. Valid values of rate are between 0.5 and 2.0. Defautlt value is 1.0 which is normal speed.
Method returns a ST_RESULT value. -
– skipAudioPlaybackInstructs
STMediaRunnermodule to skip the audio playback forwards or backwards.
Method returns a ST_RESULT value. -
– skipSSPlaybackInstructs
STMediaRunnermodule to skip and play audio from another location in the text.
Method returns a ST_RESULT value. -
– getSSEngineStateRetrieves the speech synthesizer engine state.
Method returns a STSSEngineState value. -
– getSSVoicesRetrieves the voices available for a speech synthesizer engine. If ssEngine is not specified then the voices of the active speech synthesizer engine are retrieved.
Method returns an array of voice tuples, each contains a set of voice parameters. -
– getSelectedSSVoiceRetrieves the last selected voice for a speech synthesizer engine. If ssEngine is not specified then the selected voice of the active speech synthesizer engine is retrieved.
Method returns a a tuple containing the selected voice parameters. -
– selectDefaultSSVoiceSelects a default speech synthesis voice from the default speech synthesizer engine and activates the default speech synthesiser engine. The default speech synthesizer engine is Apple Speech Synthesizer (AppleSS). The default voice selected is the first female US english voice of the highest qualiity available.
Method returns a ST_RESULT value.
For Apple SS, to find all voices on an apple mobile device, navigate to Settings–>Accessibility–>(Spoken Content OR Read & Speak)–>Voices and download the desired voice if not already downloaded. -
– selectSSVoiceSelects a speech synthesis voice. If ssEngine is not specified then the voice is selected from the active speech synthesizer engine. if ssEngine is specified then voice is selected from that engine and the engine is activated. The voice is selected according to the following prioritized rules: - Priority 1: Match by identifier - Priority 2: Match by name - Priority 3: Match by gender, language, and quality - Priority 4: Match by gender and language, highest quality - Priority 5: Match by gender and quality, US English - Priority 6: Match by language and quality, first female then male - Priority 7: Match by gender, highest quality, US English - Priority 8: Match by language, first female then male, highest quality - Priority 9: Match by quality, US English, first female then male
Method returns a ST_RESULT value.
For Apple SS, to find all voices on an apple mobile device, navigate to Settings–>Accessibility–>(Spoken Content OR Read & Speak)–>Voices and download the desired voice if not already downloaded. -
– selectSSEngineSelects a speech synthesis engine. If ssEngine is not valid then the previously selected speech synthesis engine selected remains active.
Method returns a ST_RESULT value.
-
– getSelectedSSEngineRetrieves the currently selected speech synthesis engine.
Method returns the speech synthesizer engine name that is currently selected.
-
– loadSSAliases(aliasFile)Loads speech synthesizer aliases for specidic words from a file. A speech synthesizer substitutes the specific words for their aliases in the text before speech synthesis. Example of entries in an alias file:
GitHub: Git Hub
iOS: eye oh ess
Antoine: Antwan
Mounir: Mooneer
Method returns a ST_RESULT value. -
– loadSSAliases(aliasDictionary)Loads speech synthesizer aliases for specidic words from a dictionary of strings, where each string pair represents a single alias entry.. A speech synthesizer substitutes the specific words for their aliases in the text before speech synthesis. Example of entries in a dictionary:
let aliases:[String: String] = [“GitHub”: “Git Hub”, “iOS”: “eye oh ess”, “Antoine”: “Antwan”, “Mounir”: “Mooneer”]
Method returns a ST_RESULT value. -
– loadSSPhonemes(phonemeFile)Loads speech synthesizer phoneme sets for specidic words from a file. Only IPA notation phonemes are supported. A speech synthesizer substitutes the specific words for their phonemes before speech synthesis. Example of entries in an phoneme file:
John: dʒɒn
Mounir: munɪɹ
hello: həˈloʊ
world: wɜːrld
Method returns a ST_RESULT value. -
– loadSSPhonemes(phonemeDictionary)Loads speech synthesizer phonemes for specidic words from a dictionary of strings, where each string pair represents a single word with its associted set of phonemes. Only IPA notation phonemes are supported. A speech synthesizer substitutes the specific words for their phonemes before speech synthesis. Example of entries in a dictionary::
let aliases:[String: String] = [“John”: “dʒɒn”, “Mounir”: “munɪɹ”, “hello”: “həˈloʊ”, “world”: “wɜːrld”]
Method returns a ST_RESULT value. -
– initializeAudioRecorderInitializes the audio recorder media component of the media module. This method must be called before calling other methods that require functionlity such as audio recording and speech recognition.
Method returns a ST_RESULT value. -
– releaseAudioRecorderReleases the audio recorder media component.
Method returns a ST_RESULT value. -
– requestMicrophonePermissionRequests permission for application to use device microphone in order to collect audio from the microphone. If the permission for the application has not yet been granted or denied, the
STMediaRunnermodule returns the permission decision asynchronously through a media noitification event to the application.
STMediaRunnermodule sends real time event notifications about status of permission request to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value:
- ST_PERMISSION_GRANTED or ST_PERMISSION DENIED if the permission has been previously granted or denied.
- ST_PERMISSION_WAIT indicating that the permission to use the microphone is being presented to the application user. User’s decision to grant or deny microphone usage is sent to the application through a notification event.
- Otherwise, another ST_RESULT value. -
– recordDeviceAudioProvides audio recording from an audio input source on a device.The audio data is saved into an audio segment. This method executes asynchronously when the method returns
ST_SUCCESS.
STMediaRunnermodule sends real time event notifications about status of audio recording to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value. -
– recordFileAudioProvides audio recording from an audio segment source to an audio segment destination. This method executes asynchronously when the method returns
ST_SUCCESS.
STMediaRunnermodule sends real time event notifications about status of audio recording to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value. -
– stopRecordAudioInstructs
STMediaRunnermodule to stop audio recording before audio recording completes. This method executes asynchronously when the method returnsST_SUCCESS.
STMediaRunnermodule sends real time event notifications about status of audio recording to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value. -
– getSREngineStateRetrieves the speech recognizer engine state.
Method returns a STSREngineState value. -
– getSelectedSREngineRetrieves the currently selected speech recognition engine.
Method returns a string containing the selected speech recognition engine.
-
– getSelectedSRLanguageCodeRetrieves the last selected language code for a speech recognizer engine. If srEngine is not specified then the selected language code of the active speech recognizer engine is retrieved.
Method returns a string containing the selected language code. -
– initializeSREngineInitializes a speech recognition engine. A speech recognizer engine must be initialized before methods that require speech recognition service from that engine are called.
Method returns a ST_RESULT value. -
– releaseSREngineReleases the speech recognition engine.
Method returns a ST_RESULT value. -
– requestSpeechRecognitionPermissionRequests permission for application to use speech recognition on collected audio data. If the permission for the application has not yet been granted or denied, the
STMediaRunnermodule returns the permission decision asynchronously through a media noitification event to the application.
STMediaRunnermodule sends real time event notifications about status of permission request to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value:
- ST_PERMISSION_GRANTED or ST_PERMISSION DENIED if the permission has been previously granted or denied.
- ST_PERMISSION_WAIT indicating that the permission to use speech recognition is being presented to the application user. User’s decision to grant or deny speech recognition is sent to the application through a notification event.
- Otherwise, another ST_RESULT value. -
– loadContextualPhrasesLoads SR Contextual Strings and their optional phonetic maps for the speech recognizer to recognize contexts differently or more accurately. A dictionary is used to pass the Contextual Strings with phonetic map entries to the speech recognizer.
Example of Contextual Strings and their optional phonetic map entries in a dictionary:
[ “Quvenzhané Wallis”: “Kwuh-ven-zha-nay Wallis”, “Gstaad”: “Shtahd”, “Ålesund”: “Oh-leh-sund”, “Quvenzhané”: “Kwuh-ven-zha-nay”, “Xóchitl”: “So-cheel”, “Saoirse”: “Sur-sha”, “Nguyễn”: “Nwin”, “Tchaikovsky”: “Chai-koff-skee”, “Gstaad”: “Shtahd”, “Ibiza”: “Ee-bee-tha” ]
Method returns a ST_RESULT value. -
– recognizeDeviceAudioProvides speech recognition on device audio data obtained from an audio input source on a device. This method executes asynchronously when the method returns
ST_SUCCESS.
STMediaRunnermodule sends real time event notifications about status of speech recognition to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value. -
– recognizeFileAudioProvides speech recognition on audio data obtained from a pre-recorded audio utterance file. The execution of this speech recognition task includes real-time streaming of audio data samples from a file to a speech recognizer, and with that, it simulates the execution of
recognizeDeviceAudiomethod which streams device audio data samples from an audio input source on a device. This method executes asynchronously when the method returnsST_SUCCESS.
STMediaRunnermodule sends real time event notifications about status of speech recognition to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value. -
– recognizeFileAudioOfflineProvides offline speech recognition on audio data obtained from a pre-recorded audio utterance file. The method performs offline speech recognition on audio samples read directly from an utternace without real-time audio streaming. This method executes asynchronously when the method returns
ST_SUCCESS.
STMediaRunnermodule sends real time event notifications about status of speech recognition to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value. -
– stopRecognizeAudioInstructs
STMediaRunnermodule to stop speech recognition before speech recognition completes. This method executes asynchronously when the method returnsST_SUCCESS.
STMediaRunnermodule sends real time event notifications about status of speech recognition to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Instance Methods
configureAudioSession
public func configureAudioSession(_ audioSessionParams: STAudioSessionParams) -> ST_RESULT
Discussion
Configures the audio session created by the STMediaRunner module.
Parameters
AudioSessionParamsThe audio session parameters as defined in STAudioSessionParams.
Method returns a ST_RESULT value.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
getComponentLogLevel
public func getComponentLogLevel(type: String) -> String?
Discussion
Retrieves the logging level for one of the STMediaRunner module components.
Media components of STMediaRunner module have the following types: “MediaRunner”, “MediaPermissions”, “AudioSession”, “AudioRecorder”, “AudioFileRecorder”, “AudioPlayer”, “AudioFilePlayer”, “AppleSR” and “AppleSS”.
Log level is a string value and is set to one of the following values: “none”, “fault”, “error”, “default”, “info”, “debug” and “verbose”.
Parameters
typeThe type of the
STMediaRunnermodule component.
Return Value
A string value representing the log level of a STMediaRunner module component.
Declared In
STMediaRunner.swift
getSREngineState
public func getSREngineState() -> STSREngineState
Discussion
Retrieves the speech recognizer engine state.
Method returns a STSREngineState value.
Return Value
A STSREngineState value.
Declared In
STMediaRunner.swift
getSSEngineState
public func getSSEngineState(ssEngine: String? = nil) -> STSSEngineState
Discussion
Retrieves the speech synthesizer engine state.
Method returns a STSSEngineState value.
Parameters
ssEngineThe speech synthesizer engine, for example “AppleSS”.
Return Value
A STSSEngineState value.
Declared In
STMediaRunner.swift
getSSVoices
public func getSSVoices(ssEngine:String? = nil) -> [(engine: String, identifier: String, name: String, language: String, gender: String, quality: String)]
Discussion
Retrieves the voices available for a speech synthesizer engine. If ssEngine is not specified then the voices of the active speech synthesizer engine are retrieved.
Method returns an array of voice tuples, each contains a set of voice parameters.
Parameters
ssEngineThe speech synthesizer engine, for example “AppleSS”.
Return Value
An array of voice tuples.
Declared In
STMediaRunner.swift
getSelectedSREngine
public func getSelectedSREngine() -> String?
Discussion
Retrieves the currently selected speech recognition engine.
Method returns a string containing the selected speech recognition engine.
Return Value
The name of the selected speech recognition engine.
Declared In
STMediaRunner.swift
getSelectedSRLanguageCode
public func getSelectedSRLanguageCode(srEngine:String? = nil) -> String
Discussion
Retrieves the last selected language code for a speech recognizer engine. If srEngine is not specified then the selected language code of the active speech recognizer engine is retrieved.
Method returns a string containing the selected language code.
Parameters
srEngineThe speech recognizer engine.
Return Value
A string containing the selected language code.
Declared In
STMediaRunner.swift
getSelectedSSEngine
public func getSelectedSSEngine() -> String?
Discussion
Retrieves the currently selected speech synthesis engine.
Method returns the speech synthesizer engine name that is currently selected.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
getSelectedSSVoice
public func getSelectedSSVoice(ssEngine:String? = nil) -> (engine: String, identifier: String, name: String, language: String, gender: String, quality: String)
Discussion
Retrieves the last selected voice for a speech synthesizer engine. If ssEngine is not specified then the selected voice of the active speech synthesizer engine is retrieved.
Method returns a a tuple containing the selected voice parameters.
Parameters
ssEngineThe speech synthesizer engine, for example “AppleSS”.
Return Value
A tuple containing the selected voice parameters.
Declared In
STMediaRunner.swift
initializeAudioPlayer
public func initializeAudioPlayer() -> ST_RESULT
Discussion
Initializes the audio player media component of the media module. This method must be called before calling other methods that require functionlity such as audio playback.
Method returns a ST_RESULT value.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
initializeAudioRecorder
public func initializeAudioRecorder() -> ST_RESULT
Discussion
Initializes the audio recorder media component of the media module. This method must be called before calling other methods that require functionlity such as audio recording and speech recognition.
Method returns a ST_RESULT value.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
initializeSREngine
public func initializeSREngine(srEngine:String? = nil, languageCode:String? = nil) -> ST_RESULT
Discussion
Initializes a speech recognition engine. A speech recognizer engine must be initialized before methods that require speech recognition service from that engine are called.
Method returns a ST_RESULT value.
Parameters
srEngineThe speech recognizer engine to use for speech recognition. For example: “Apple”
languageCodeThe language for speech recognizer to recognize. Speech reocgnition supports many languages. Example: “en-us” for american english.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
initialize
public func initialize() -> ST_RESULT
Discussion
Initializes the STMediaRunner module. This method must be called to set up all the media components and to enable media procesing using these components. Some of the STMediaRunner module components must also be initialized using their respective initilization methods after this method is called.
Sample implementation code:
let mediaRunner = STMediaRunner.shared
let result:ST_RESULT = mediaRunner.initialize()
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
loadContextualPhrases
public func loadContextualPhrases(dictContextualPhrases:[String: String]) -> ST_RESULT
Discussion
Loads SR Contextual Strings and their optional phonetic maps for the speech recognizer to recognize contexts differently or more accurately. A dictionary is used to pass the Contextual Strings with phonetic map entries to the speech recognizer.
Example of Contextual Strings and their optional phonetic map entries in a dictionary:
[
“Quvenzhané Wallis”: “Kwuh-ven-zha-nay Wallis”,
“Gstaad”: “Shtahd”,
“Ålesund”: “Oh-leh-sund”,
“Quvenzhané”: “Kwuh-ven-zha-nay”,
“Xóchitl”: “So-cheel”,
“Saoirse”: “Sur-sha”,
“Nguyễn”: “Nwin”,
“Tchaikovsky”: “Chai-koff-skee”,
“Gstaad”: “Shtahd”,
“Ibiza”: “Ee-bee-tha”
]
Method returns a ST_RESULT value.
Parameters
dictContextualPhrasesThe dictionary containing the contextual phrases and their optional phonetic maps.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
loadSSAliases(aliasFile)
public func loadSSAliases(aliasFile: String) -> ST_RESULT
Discussion
Loads speech synthesizer aliases for specidic words from a file. A speech synthesizer substitutes the specific words for their aliases in the text before speech synthesis. Example of entries in an alias file:
GitHub: Git Hub
iOS: eye oh ess
Antoine: Antwan
Mounir: Mooneer
Method returns a ST_RESULT value.
Parameters
aliasFileThe file pathname URL for the file contaning the alias entries.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
loadSSAliases(aliasDictionary)
public func loadSSAliases(aliasList: [String: String]) -> ST_RESULT
Discussion
Loads speech synthesizer aliases for specidic words from a dictionary of strings, where each string pair represents a single alias entry.. A speech synthesizer substitutes the specific words for their aliases in the text before speech synthesis. Example of entries in a dictionary:
let aliases:[String: String] = [“GitHub”: “Git Hub”, “iOS”: “eye oh ess”, “Antoine”: “Antwan”, “Mounir”: “Mooneer”]
Method returns a ST_RESULT value.
Parameters
aliasListThe dictionary containing the speech synthesizer alias entries.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
loadSSPhonemes(phonemeFile)
public func loadSSPhonemes(phonemeFile: String) -> ST_RESULT
Discussion
Loads speech synthesizer phoneme sets for specidic words from a file. Only IPA notation phonemes are supported. A speech synthesizer substitutes the specific words for their phonemes before speech synthesis. Example of entries in an phoneme file:
John: dʒɒn
Mounir: munɪɹ
hello: həˈloʊ
world: wɜːrld
Method returns a ST_RESULT value.
Parameters
phonemeFileThe file pathname URL for the file contaning the phoneme entries.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
loadSSPhonemes(phonemeDictionary)
public func loadSSPhonemes(phonemeList: [String: String]) -> ST_RESULT
Discussion
Loads speech synthesizer phonemes for specidic words from a dictionary of strings, where each string pair represents a single word with its associted set of phonemes. Only IPA notation phonemes are supported. A speech synthesizer substitutes the specific words for their phonemes before speech synthesis. Example of entries in a dictionary::
let aliases:[String: String] = [“John”: “dʒɒn”, “Mounir”: “munɪɹ”, “hello”: “həˈloʊ”, “world”: “wɜːrld”]
Method returns a ST_RESULT value.
Parameters
aliasListThe dictionary containing the speech synthesizer phonemes entries.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
pauseAudioPlayback
public func pauseAudioPlayback() -> ST_RESULT
Discussion
Instructs STMediaRunner module to pause audio playback. This method executes asynchronously when the method returns ST_SUCCESS.
STMediaRunner module sends real time event notifications about status of audio playback to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
playAudio
public func playAudio(_ mediaJobID: String, audioSegment: STAudioSegment, audioPlayParams: STAudioPlayParams?, lastAudioSegmentInCollection: Bool? = true) -> ST_RESULT
Discussion
Provides audio playback of an audio segment. Audio segment can be a recorded audio file or real-time synthesized speech provided by a speech synthesizer for text. This method executes asynchronously when the method returns ST_SUCCESS.
STMediaRunner module sends real time event notifications about status of audio playback to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Parameters
mediaJobIDThe ID of a media job assigned by the application to the execution of the play audio task. Client will receive this media job ID with all event notifications and callbacks associated with the play audio task.
AudioSegmentThe audio segment to process for audio playback as defined in STAudioSegment.
AudioPlayParamsThe paramaters for audio playback as defined in STAudioPlayParams.
bLastAudioSegmentInCollectionThis parameter tells the media framework whether this audio segment is the last audio segment to be played as part of a collection of audio segments. Audio recording and speech recognition that are active during audio playback need to know whehter an audio segment finishing audio playback is the last audio segment or not.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
recognizeDeviceAudio
public func recognizeDeviceAudio(_ mediaJobID:String, srTaskID:String, srParams:STSRParams?, audioRecordParams:STAudioRecordParams?, recordUtteranceAudio:Bool?) -> ST_RESULT
Discussion
Provides speech recognition on device audio data obtained from an audio input source on a device. This method executes asynchronously when the method returns ST_SUCCESS.
STMediaRunner module sends real time event notifications about status of speech recognition to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Parameters
mediaJobIDThe ID of a media job assigned by the application to the execution of the speech recognition task. Client will receive this media job ID with all event notifications and callbacks associated with the speech recognition task.
srTaskIDThe speech recognition task ID assigned to the speech recognition task by the client..
srParamsThe paramaters for executing the speech recognition session as defined in STSRParams.
audioRecordParamsThe paramaters for audio recording to be performed during speecch recognition as defined in STAudioRecordParams. Speech recognition on device audio utilizes audio recording to collect audio from an audio input source on a device. audioRecordParams aslo provides granular management over the durartion of a speech recognition session.
recordUtteranceAudioUsed for optionally collecting and storing speech recognition audio recorded into utterance files.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
recognizeFileAudio
public func recognizeFileAudio(_ mediaJobID:String, srTaskID:String, audioFile:String, srParams:STSRParams?, audioRecordParams:STAudioRecordParams?, recordUtteranceAudio:Bool?) -> ST_RESULT
Discussion
Provides speech recognition on audio data obtained from a pre-recorded audio utterance file. The execution of this speech recognition task includes real-time streaming of audio data samples from a file to a speech recognizer, and with that, it simulates the execution of recognizeDeviceAudio method which streams device audio data samples from an audio input source on a device. This method executes asynchronously when the method returns ST_SUCCESS.
STMediaRunner module sends real time event notifications about status of speech recognition to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Parameters
mediaJobIDThe ID of a media job assigned by the application to the execution of the speech recognition task. Client will receive this media job ID with all event notifications and callbacks associated with the speech recognition task.
srTaskIDThe speech recognition task ID assigned to the speech recognition task by the client..
audioFileThe audio file pathname URL of the utterence containing the audio to send to the speech recognizer.
srParamsThe paramaters for executing the speech recognition session as defined in STSRParams.
audioRecordParamsThe paramaters for audio recording as defined in STAudioRecordParams. Speech recognition on file audio utilizes audio recording to collect audio from the audio playback of
audioFile. audioRecordParams aslo provides granular management over the durartion of a speech recognition session.
recordUtteranceAudioUsed for optionally collecting and storing speech recognition audio recorded into utterance files.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
recognizeFileAudioOffline
public func recognizeFileAudio(_ mediaJobID:String, srTaskID:String, audioFile:String, srParams:STSRParams?, audioRecordParams:STAudioRecordParams?, recordUtteranceAudio:Bool?) -> ST_RESULTOffline
Discussion
Provides offline speech recognition on audio data obtained from a pre-recorded audio utterance file. The method performs offline speech recognition on audio samples read directly from an utternace without real-time audio streaming. This method executes asynchronously when the method returns ST_SUCCESS.
STMediaRunner module sends real time event notifications about status of speech recognition to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Parameters
mediaJobIDThe ID of a media job assigned by the application to the execution of the speech recognition task. Client will receive this media job ID with all event notifications and callbacks associated with the speech recognition task.
srTaskIDThe speech recognition task ID assigned to the speech recognition task by the client..
audioFileThe audio file pathname URL of the utterence containing the audio to send to the speech recognizer.
srParamsThe paramaters for executing the speech recognition session as defined in STSRParams.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
recordDeviceAudio
public func recordDeviceAudio(_ mediaJobID:String, audioRecordParams:STAudioRecordParams) -> ST_RESULT
Discussion
Provides audio recording from an audio input source on a device.The audio data is saved into an audio segment. This method executes asynchronously when the method returns ST_SUCCESS.
STMediaRunner module sends real time event notifications about status of audio recording to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Parameters
mediaJobIDThe ID of a media job assigned by the application to the execution of the audio recording task. Client will receive this media job ID with all event notifications and callbacks associated with the audio recording task.
AudioRecordParamsThe paramaters for audio recording as defined in STAudioRecordParams.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
recordFileAudio
public func recordFileAudio(_ mediaJobID:String, sourceAudioPath: String, sourceAudioFile: String, audioRecordParams: STAudioRecordParams) -> ST_RESULT
Discussion
Provides audio recording from an audio segment source to an audio segment destination. This method executes asynchronously when the method returns ST_SUCCESS.
STMediaRunner module sends real time event notifications about status of audio recording to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Parameters
mediaJobIDThe ID of a media job assigned by the application to the execution of the audio recording task. Client will receive this media job ID with all event notifications and callbacks associated with the audio recording task.
sourceAudioPathThe URL path for the source audio.
sourceAudioFileThe file name of the audio source file.
AudioRecordParamsThe paramaters for audio recording as defined in STAudioRecordParams.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
requestMicrophonePermission
public func requestMicrophonePermission() -> ST_RESULT
Discussion
Requests permission for application to use device microphone in order to collect audio from the microphone. If the permission for the application has not yet been granted or denied, the STMediaRunner module returns the permission decision asynchronously through a media noitification event to the application.
STMediaRunner module sends real time event notifications about status of permission request to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value:
- ST_PERMISSION_GRANTED or ST_PERMISSION DENIED if the permission has been previously granted or denied.
- ST_PERMISSION_WAIT indicating that the permission to use the microphone is being presented to the application user. User’s decision to grant or deny microphone usage is sent to the application through a notification event.
- Otherwise, another ST_RESULT value.
Return Value
ST_PERMISSION_GRANTED, ST_PERMISSION DENIED or ST_PERMISSION_WAIT if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
requestSpeechRecognitionPermission
public func requestSpeechRecognitionPermission() -> ST_RESULT
Discussion
Requests permission for application to use speech recognition on collected audio data. If the permission for the application has not yet been granted or denied, the STMediaRunner module returns the permission decision asynchronously through a media noitification event to the application.
STMediaRunner module sends real time event notifications about status of permission request to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value:
- ST_PERMISSION_GRANTED or ST_PERMISSION DENIED if the permission has been previously granted or denied.
- ST_PERMISSION_WAIT indicating that the permission to use speech recognition is being presented to the application user. User’s decision to grant or deny speech recognition is sent to the application through a notification event.
- Otherwise, another ST_RESULT value.
Return Value
ST_PERMISSION_GRANTED, ST_PERMISSION DENIED or ST_PERMISSION_WAIT if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
resetAudioPlaybackParams
public func resetAudioPlaybackParams()
Discussion
Instructs STMediaRunner module to reset audio playback parameters before next audio playback.
Declared In
STMediaRunner.swift
resumeAudioPlayback
public func resumeAudioPlayback() -> ST_RESULT
Discussion
Instructs STMediaRunner module to resume audio playback. This method executes asynchronously when the method returns ST_SUCCESS.
STMediaRunner module sends real time event notifications about status of audio playback to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
routeDeviceAudioOutput
public func routeDeviceAudioOutput(_ outputRoute: STAudioSessionOutputRoute) -> ST_RESULT
Discussion
Routes audio playback to a specific audio output destination on a device. Example is to route audio to a device internal speaker or to the device external speaker.
Method returns a ST_RESULT value.
Parameters
outputRouteThe audio session output route parameters as defined in STAudioSessionOutputRoute.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
selectDefaultSSVoice
public func selectDefaultSSVoice() -> ST_RESULT
Discussion
Selects a default speech synthesis voice from the default speech synthesizer engine and activates the default speech synthesiser engine. The default speech synthesizer engine is Apple Speech Synthesizer (AppleSS). The default voice selected is the first female US english voice of the highest qualiity available.
Method returns a ST_RESULT value.
For Apple SS, to find all voices on an apple mobile device, navigate to Settings–>Accessibility–>(Spoken Content OR Read & Speak)–>Voices and download the desired voice if not already downloaded.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
selectSSEngine
public func selectSSEnginessEngine:String) -> ST_RESULT
Discussion
Selects a speech synthesis engine. If ssEngine is not valid then the previously selected speech synthesis engine selected remains active.
Method returns a ST_RESULT value.
Parameters
ssEngineThe speech synthesizer engine name.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
selectSSVoice
public func selectSSVoice(ssEngine: String? = nil, identifier: String? = nil, name: String? = nil, language: String? = nil, gender: String? = nil, quality: String? = nil) -> ST_RESULT
Discussion
Selects a speech synthesis voice. If ssEngine is not specified then the voice is selected from the active speech synthesizer engine. if ssEngine is specified then voice is selected from that engine and the engine is activated.
The voice is selected according to the following prioritized rules:
- Priority 1: Match by identifier
- Priority 2: Match by name
- Priority 3: Match by gender, language, and quality
- Priority 4: Match by gender and language, highest quality
- Priority 5: Match by gender and quality, US English
- Priority 6: Match by language and quality, first female then male
- Priority 7: Match by gender, highest quality, US English
- Priority 8: Match by language, first female then male, highest quality
- Priority 9: Match by quality, US English, first female then male
Method returns a ST_RESULT value.
For Apple SS, to find all voices on an apple mobile device, navigate to Settings–>Accessibility–>(Spoken Content OR Read & Speak)–>Voices and download the desired voice if not already downloaded.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
setAudioPlaybackPitch
public func setAudioPlaybackPitch(pitch:Float) -> ST_RESULT
Discussion
Instructs STMediaRunner module to change the audio playback pitch. Valid values of rate are between -2.0 and 2.0. Defautlt value is 0.0 which is normal pitch. Each 1.0 interval represnts one octave. each octave is 1200 cents. One musical semitone is equal to 100 cents. So each semitome is a value of 0.0833.
Method returns a ST_RESULT value.
Parameters
pitchThe pitch of audio playback as a float. Value between -2.0 and 2.0.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
setAudioPlaybackRate
public func setAudioPlaybackRate(rate:Float) -> ST_RESULT
Discussion
Instructs STMediaRunner module to change the audio playback rate. Valid values of rate are between 0.5 and 2.0. Defautlt value is 1.0 which is normal speed.
Method returns a ST_RESULT value.
Parameters
rateThe rate of audio playback as a float. Value between 0.5 and 2.0.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
setAudioPlaybackVolume
public func setAudioPlaybackVolume(volume:Float) -> ST_RESULT
Discussion
Instructs STMediaRunner module to change the audio playback volume. Valid values of volume are between 0.0 and 1.0. Defautlt value is 1.0 which is full volume..
Method returns a ST_RESULT value.
Parameters
volumeThe volume of audio playback as a float. Value between 0.0 and 1.0.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
setComponentsLogLevels
public func setComponentsLogLevels(logLevels:[String:String])
Discussion
Sets the log levels of the STMediaRunner module components. Usually, this method is invoked before initializing the STMediaRunner shared object.
STMediaRunner module contains many media components. Logging for each media component can be controlled independently.
On Apple devices Unified logging is utilized. All logs are available in Apple’s Console application. Also all logs are visible in Xcode output console when running the application in Xcode in debug mode.
Here is a list of the media components for STMediaRunner module:
- “MediaRunner”
- “MediaPermissions”
- “AudioSession”
- “AudioPlayer”
- “AudioFilePlayer”
- “AudioRecorder”
- “AudioFileRecorder”
- “AppleSS”
- “AppleSR”
The following are the valid log levels:
- “none”
- “fault”
- “error”
- “default”
- “info”
- “debug”
- “verbose”
Default log level for all media components is: “default”.
Sample implementation code:
let logLevels:[String:String] = ["AudioPlayer":"verbose", "AppleSS":"error", "AudioSession":"none"]
let mediaRunner = STMediaRunner.shared
mediaRunner.setLogLevel(logLevel: "debug")
mediaRunner.setComponentsLogLevels(logLevels: logLevels)
mediaRunner.initialize()
Parameters
logLevelsThe log levels is a dictionary of key value string pairs where key is the media component name and the value is its log level.
Declared In
STMediaRunner.swift
setLogLevel
public func setLogLevel(logLevel:String)
Discussion
Sets the log level of the STMediaRunner media module. Usually, this method is invoked before initializing the STMediaRunner shared object.
On Apple devices Unified logging is utilized. All logs are available in Apple’s Console application. Also all logs are visible in Xcode output console when running the application in Xcode in debug mode.
The following are the valid log levels:
- “none”
- “fault”
- “error”
- “default”
- “info”
- “debug”
- “verbose”
Default log level is: “default”.
Sample implementation code:
let mediaRunner = STMediaRunner.shared
mediaRunner.setLogLevel(logLevel:"debug")
mediaRunner.initialize()
Parameters
logLevelThe log level.
Declared In
STMediaRunner.swift
skipAudioPlayback
public func skipAudioPlayback(forward: Bool, duration: Int32) -> ST_RESULT
Discussion
Instructs STMediaRunner module to skip the audio playback forwards or backwards.
Method returns a ST_RESULT value.
Parameters
forwardSkips forward if true or skips backwards if false.
durationThe length of the skip in milliseconds.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
skipSSPlayback
public func skipSSPlayback(skipType: STSS_SkipType, targetText: String, forward: Bool , count: Int) -> ST_RESULT
Discussion
Instructs STMediaRunner module to skip and play audio from another location in the text.
Method returns a ST_RESULT value.
Parameters
skipTypeDefines the function to use for locating the new location in text to synthesize and play audio as defined by STSS_SkipType.
targeTextThe text to search for if skipType requires the text.
forwardSearches for the text location forward if true or backwards if false.
countDefines the number of target texts, phrases, paragraphs, pages or sections to skip during search for the text location
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
stopAudioPlayback
public func stopAudioPlayback() -> ST_RESULT
Discussion
Instructs STMediaRunner module to stop audio playback before audio playback completes. This method executes asynchronously when the method returns ST_SUCCESS.
STMediaRunner module sends real time event notifications about status of audio playback to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
stopRecognizeAudio
public func stopRecognizeAudio(isCancel: Bool) -> ST_RESULT
Discussion
Instructs STMediaRunner module to stop speech recognition before speech recognition completes. This method executes asynchronously when the method returns ST_SUCCESS.
STMediaRunner module sends real time event notifications about status of speech recognition to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Parameters
isCancelIf false, a speech recognition hypthesis, if availalble is returned asynchronously to the client.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift
stopRecordAudio
public func stopRecordAudio() -> ST_RESULT
Discussion
Instructs STMediaRunner module to stop audio recording before audio recording completes. This method executes asynchronously when the method returns ST_SUCCESS.
STMediaRunner module sends real time event notifications about status of audio recording to clients that subclass STEventsObserverDelegate and implement logic in STMedia_EventNotification function.
Method returns a ST_RESULT value.
Return Value
ST_SUCCESS if successul. Otherwise, another ST_RESULT value.
Declared In
STMediaRunner.swift