| Package | com.aispeech |
| Class | public class RecorderLib |
| Inheritance | RecorderLib flash.display.Sprite |
RecorderLib is the key component ASSDK provides. Use RecorderLib to accomplish recording, AISpeech API requesting, as well as replaying. It integrates microphone device, recorder, core requester and network connection. It supports RTMP connection to AISpeech's clouding service, as well as the local service.
RecorderLib extends from flash.display.Sprite, having its own vierwing components, showing microphone device management UIs.
Online Tutorials:
RecorderLib dispatches the following events.
FactoryEvent
NetEvent
CoreRequesterEvent
MicrophoneDeviceEvent
RecorderEvent
See also
| Property | Defined By | ||
|---|---|---|---|
| connectionState : String [read-only]
| RecorderLib | ||
| coreRequesterState : String [read-only]
| RecorderLib | ||
| dingPlayEnabled : Boolean [write-only]
Set play Ding
Before staring recoding, RecorderLib plays a 'ding' to notify users. | RecorderLib | ||
| dingVolume : Number
Get "ding" volume, value between 0 and 100
| RecorderLib | ||
| isIdle : Boolean [read-only] | RecorderLib | ||
| micActivityLevel : Number [read-only]
Get microphone activity level, value between 0 and 100
| RecorderLib | ||
| micGain : Number
Get microphone gain, value between 0 and 100
| RecorderLib | ||
| microphoneDeviceState : String [read-only]
| RecorderLib | ||
| recorderState : String [read-only]
| RecorderLib | ||
| replayVolume : Number
Get replay volume, value between 0 and 100
| RecorderLib | ||
| state : Object [read-only]
Get RecorderLib's components' state info and configuation info. | RecorderLib | ||
| tsIdle : int [read-only] | RecorderLib | ||
| tsIDLEState : int [static]
Timestamp of the start of IDLE state
| RecorderLib | ||
| Method | Defined By | ||
|---|---|---|---|
Constructor
| RecorderLib | ||
disconnect(reconnect:Boolean = false):void
Disconnect from the server
RecorderLib has build-in reconnecting function. | RecorderLib | ||
hideMicrophonePanel():String | RecorderLib | ||
init(params:Object):String
Initialise a RecorderLib instance. | RecorderLib | ||
reconnect():void
Reconnect to the server
Perform reconnecting immediately if the current connection is connected
| RecorderLib | ||
showMicrophonePanel(setting:Object = null):String
Show MicrophonePanel, which contains three microphone related meters
| RecorderLib | ||
startRecord(param:Object):String
Start recording
| RecorderLib | ||
startReplay(param:Object):String
Start replay locally cached user's record. | RecorderLib | ||
stopRecord():String
Stop recording
RecorderLib will automatically stop recording after the time setting by recordLength in
param of the startRecord() method. | RecorderLib | ||
stopReplay():String
Stop replaying
RecorderLib will automatically stop replaying. | RecorderLib | ||
| connectionState | property |
connectionState:String [read-only]
public function get connectionState():StringSee also
| coreRequesterState | property |
coreRequesterState:String [read-only]
public function get coreRequesterState():StringSee also
| dingPlayEnabled | property |
dingPlayEnabled:Boolean [write-only] Set play Ding
Before staring recoding, RecorderLib plays a 'ding' to notify users. This setter is to toggle this feature.
public function set dingPlayEnabled(value:Boolean):void| dingVolume | property |
dingVolume:NumberGet "ding" volume, value between 0 and 100
public function get dingVolume():Number public function set dingVolume(value:Number):void| isIdle | property |
isIdle:Boolean [read-only] public function get isIdle():Boolean| micActivityLevel | property |
micActivityLevel:Number [read-only] Get microphone activity level, value between 0 and 100
public function get micActivityLevel():Number| micGain | property |
micGain:NumberGet microphone gain, value between 0 and 100
public function get micGain():Number public function set micGain(value:Number):void| microphoneDeviceState | property |
microphoneDeviceState:String [read-only]
public function get microphoneDeviceState():StringSee also
| recorderState | property |
recorderState:String [read-only]
public function get recorderState():StringSee also
| replayVolume | property |
replayVolume:NumberGet replay volume, value between 0 and 100
public function get replayVolume():Number public function set replayVolume(value:Number):void| state | property |
state:Object [read-only] Get RecorderLib's components' state info and configuation info. Includes:
{
microphone
state
connection
state
uri
throutput (bytes/second)
latency (ms)
latencyCheckSuccess
coreRequester
state
recorder
state
connectionFactory
history (Array)
latencyServiceAvailability (Array)
recorderLib
isIdle
tsIdle
}
public function get state():ObjectSee also
| tsIdle | property |
tsIdle:int [read-only] public function get tsIdle():int| tsIDLEState | property |
public static var tsIDLEState:intTimestamp of the start of IDLE state
| RecorderLib | () | Constructor |
public function RecorderLib()Constructor
var recorder:RecorderLib = new RecorderLib();
| disconnect | () | method |
public function disconnect(reconnect:Boolean = false):voidDisconnect from the server
RecorderLib has build-in reconnecting function. Once the network connection is closed, RecorderLib will automatically try to reconnect.
Parameters
reconnect:Boolean (default = false) |
| hideMicrophonePanel | () | method |
public function hideMicrophonePanel():StringReturns
String |
| init | () | method |
public function init(params:Object):StringInitialise a RecorderLib instance.
Parameters
params:Object —
params is an Object. RecorderLib does not valid parameters, e.g. urlListServiceUrl must be a valid URI string
{
// two required parameters
appKey: "your application ID", required
secretKey: "your secret Key", required
// log settings
logId: "logId", default: "" (Empty logId usually means using no JSSDK)
userId:
as2sdkVersion: "2.1.1", default: "" (empty as2sdkVersion usually means using no AS2SDK)
logLevel: ["DEBUG" | "INFO" | "WARN" | "ERROR" | "FATAL"], default: refer to this._logLevel
logTarget: [1 | 2 | 3] (1:JS_ARTHROPOD, 2:ARTHROPOD, 3:NO_LOG), default: refer to this._logTarget
// microphone settings
encodingType: ["NellyMoser" | "Speex"], default: refer to MicrophoneDevice.encodingType
// microphone panel settings
showFlash: ["true" | "false"], default: refer to this.SHOW_MICROPHONE_PANEL
backgroundColor: 0xffffff, default: MicrophonePanel.BACKGROUND_COLOUR
language:["en" | "zh-CN"]
// API service settings
connectLocalService: ["true" | "false"], default: false
urlListServiceUrl: defaut: URLListFactory.URLLIST_SERVICE_URL
logServiceUrl: default: ASSDKLogBase.LOG_SERVICE_URL
defaultAPIServiceUrlArray: ("['url1', 'url2', 'url3']") default: ConnectionFactory.DEFAULT_API_SERVICE_ARRAY
localServiceUrl: default: ConnectionFactory.LOCAL_SERVICE_URL
latencyCheckServiceApplication: ":5080/v2.0/latencydetect", default: LatencyCheck.LATENCY_CHECK_APPLICATION
// core requester settings
coreTimeout: default, CoreRequesterBase._timeout
}
|
String — StatusCode
|
See also
var recorder:RecorderLib = new RecorderLib();
var params:Object = {
appKey : " your application ID",
secretKey: " your secret Key"
};
recorder.init(params);
| reconnect | () | method |
public function reconnect():voidReconnect to the server
Perform reconnecting immediately if the current connection is connected
| showMicrophonePanel | () | method |
public function showMicrophonePanel(setting:Object = null):StringShow MicrophonePanel, which contains three microphone related meters
Parameters
setting:Object (default = null) — e.g. { meter:{x:0,y:0,visible:true}, slider:{x:0,y:0,visible:false}, viewer:{x:0,y:0,visible:false} }
|
String |
| startRecord | () | method |
public function startRecord(param:Object):StringStart recording
Parameters
param:Object — param is an object. Each recording combines a speech core request. So the request parameter is send as serverParam property, which must be provided. recordLength property is cacluated with respect to the length of reference text. We suggest that: recordLength = 2500 + numChars 450, where numChars is the number of chars (for Chinese) or words (for English).
{
serverParam (ASSDK does not check serverParam, which is sent to the core directly.)
{
coreType: (en.word.score | en.sent.score.V3 | en.sent.score | en.sent.rec | en.sent.recscore.v4 | cn.sent.rec)
refText:
scoreType: (2 | 4 | 100)
grammar:
language:
confidenceThreshhold:
resource:
luaScript: (support direct lua script)
}
recordLength: [DIGIT] (ms), default refer to RecorderBase.RECORD_LENGTH
playDing: [true | false], default true
}
|
String — StatusCode
|
See also
serverParam reference: English pronunciation evaluation , English speech recognition
// assuming recorder is an instance of RecorderLib
// recorder is initialised
// we are requesting English pronunciation evaluation core.
var serverParams:Object = {
refText:"I like to play piano", // this to be updated for each core request (startRecord method)
scoreType:100, // ask score in grade 100
rank:100,
coreType:"en.sent.score", // request the English-Senetence core
userId:"xxxxxx", // if any
applicationId:"your application ID" // application ID again
};
var recorderParams:Object = {
recordLength:4750,
serverParam:serverParams
};
recorder.startRecord(recorderParams);
| startReplay | () | method |
public function startReplay(param:Object):StringStart replay locally cached user's record.
RecorderLib locally caches user's record. This replay replay any of them given the recordId. recordId is got by listening RecorderEvent.RECORDID_GOT event.
Parameters
param:Object — param is an object. if param equals {}, RecorderLib replays the latest record.
{
recordId: "recordId"
}
|
String — StatusCode
|
See also
private var _recorderId:String;
// assume recorderLib is an instance of RecorderLib
// and recorderLib is initialised
recorderLib.addEventListener(RecorderEvent.RECORDID_GOT, recorderEventHandler);
// ... accomplish recording
recorderLib.startRecord({recordId:_recordId});
// ...
private function recorderEventHandler(event:RecorderEvent):void
{
if (event.type == RecorderEvent.RECORDERID_GOT)
_recorderId = event.data as String;
}
| stopRecord | () | method |
public function stopRecord():StringStop recording
RecorderLib will automatically stop recording after the time setting by recordLength in param of the startRecord() method. This method stops recording immediately. RecorderLib starts waiting speech core's response right after the recording stops.
ReturnsString — StatusCode
|
See also
| stopReplay | () | method |
public function stopReplay():StringStop replaying
RecorderLib will automatically stop replaying. This method stops recording immediately.
ReturnsString — StatusCode
|
See also