ActionScript SDK for AISpeech APIAll Packages | All Classes | Index | Frames
RecorderLib
 
Packagecom.aispeech
Classpublic class RecorderLib
InheritanceRecorderLib Inheritance 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

  1. READY
  2. EXCEPTION_TIMEOUT

NetEvent

  1. EXCEPTION_CLOSED

CoreRequesterEvent

  1. RESULT
  2. EXCEPTION_TIMEOUT
  3. EXCEPTION_PARAMETERS_ERROR
  4. EXCEPTION_RESPONSE_ERROR

MicrophoneDeviceEvent

  1. MIC_ALLOWED
  2. EXCEPTION_MIC_NOT_ALLOWED
  3. EXCEPTION_MIC_NOT_FOUND
  4. EXCEPTION_MMSCFG_SETTING

RecorderEvent

  1. RECORD_STARTED
  2. RECORD_STOPPED
  3. REPLAY_STARTED
  4. REPLAY_STOPPED
  5. RECORDID_GOT
  6. EXCEPTION_NO_RECORD

See also

com.aispeech.events.FactoryEvent
com.aispeech.events.NetEvent
com.aispeech.events.RecorderEvent
com.aispeech.events.CoreRequesterEvent
com.aispeech.events.MicrophoneDeviceEvent
com.aispeech.events.StatusCode


Public Properties
 PropertyDefined 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
Public Methods
 MethodDefined By
  
Constructor
RecorderLib
  
disconnect(reconnect:Boolean = false):void
Disconnect from the server RecorderLib has build-in reconnecting function.
RecorderLib
  
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
Property Detail
connectionStateproperty
connectionState:String  [read-only]


Implementation
    public function get connectionState():String

See also

coreRequesterStateproperty 
coreRequesterState:String  [read-only]


Implementation
    public function get coreRequesterState():String

See also

dingPlayEnabledproperty 
dingPlayEnabled:Boolean  [write-only]

Set play Ding

Before staring recoding, RecorderLib plays a 'ding' to notify users. This setter is to toggle this feature.


Implementation
    public function set dingPlayEnabled(value:Boolean):void
dingVolumeproperty 
dingVolume:Number

Get "ding" volume, value between 0 and 100


Implementation
    public function get dingVolume():Number
    public function set dingVolume(value:Number):void
isIdleproperty 
isIdle:Boolean  [read-only]


Implementation
    public function get isIdle():Boolean
micActivityLevelproperty 
micActivityLevel:Number  [read-only]

Get microphone activity level, value between 0 and 100


Implementation
    public function get micActivityLevel():Number
micGainproperty 
micGain:Number

Get microphone gain, value between 0 and 100


Implementation
    public function get micGain():Number
    public function set micGain(value:Number):void
microphoneDeviceStateproperty 
microphoneDeviceState:String  [read-only]


Implementation
    public function get microphoneDeviceState():String

See also

recorderStateproperty 
recorderState:String  [read-only]


Implementation
    public function get recorderState():String

See also

replayVolumeproperty 
replayVolume:Number

Get replay volume, value between 0 and 100


Implementation
    public function get replayVolume():Number
    public function set replayVolume(value:Number):void
stateproperty 
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
         }
         


Implementation
    public function get state():Object

See also

tsIdleproperty 
tsIdle:int  [read-only]


Implementation
    public function get tsIdle():int
tsIDLEStateproperty 
public static var tsIDLEState:int

Timestamp of the start of IDLE state

Constructor Detail
RecorderLib()Constructor
public function RecorderLib()

Constructor


Example
New a RecorderLib instance
             var recorder:RecorderLib = new RecorderLib();
         
Method Detail
disconnect()method
public function disconnect(reconnect:Boolean = false):void

Disconnect 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():String

Returns
String
init()method 
public function init(params:Object):String

Initialise a RecorderLib instance.

Parameters

params:Object

params is an Object. appKey and secretKey are two required properties.

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
         }
         

Returns
String — StatusCode
  • 50004: Successful
  • 50005: Parameters error
  • 50003: Microphone device not available

See also


Example
Initialise a RecorderLib instance
             var recorder:RecorderLib = new RecorderLib();
                var params:Object = {
                 appKey : " your application ID",
                 secretKey: " your secret Key"
             };
             recorder.init(params);
         
reconnect()method 
public function reconnect():void

Reconnect to the server

Perform reconnecting immediately if the current connection is connected

showMicrophonePanel()method 
public function showMicrophonePanel(setting:Object = null):String

Show 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} }

Returns
String
startRecord()method 
public function startRecord(param:Object):String

Start 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
         }
         

Returns
String — StatusCode
  • 50004: Successful
  • 50006: RecorderLib instance not initialised
  • 50005: Parameters error, usually due to serverParam not provided
  • 50003: Microphone device not available
  • 50002: Microphoen device muted
  • 50110: Connection not ready
  • 50353: Recorder state error
  • 50415: Local wave recorder not ready

See also


Example
Start recording

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):String

Start 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"
         }
         

Returns
String — StatusCode
  • 50004: Successful
  • 50006: RecorderLib instance not initialised
  • 50353: No local cached record, usually due to not making a record
  • 50354: Found no local cached recording with respect to a recordId
  • 50353: Recorder state error

See also


Example
Replay
             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():String

Stop 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.

Returns
String — StatusCode
  • 50004: Successful
  • 50006: RecorderLib instance not initialised
  • 50353: Recorder state error

See also

stopReplay()method 
public function stopReplay():String

Stop replaying

RecorderLib will automatically stop replaying. This method stops recording immediately.

Returns
String — StatusCode
  • 50004: Successful
  • 50006: RecorderLib instance not initialised
  • 50353: Recorder state error

See also