AsrModule
ClassAllows the Lens to incorporate voice transcription with higher quality than the VoiceMlModule and supports a vast number of different languages.
- Snapchat: not supported
- SPECS: fully supported
- Camera Kit Web: not supported
- Camera Kit Mobile: not supported
- SnapchatNot supported — Available on SPECS only
- SPECSFully supported
- Camera Kit WebNot supported — Available on SPECS only
- Camera Kit MobileNot supported — Available on SPECS only
Since Lens Scripting v309
Index
Example
JavaScript
const asrModule = require("LensStudio:AsrModule");
function onTranscriptionError(errorCode) {
print(`onTranscriptionErrorCallback errorCode: ${errorCode}`);
switch (errorCode) {
case AsrModule.AsrStatusCode.InternalError:
print("stopTranscribing: Internal Error");
break;
case AsrModule.AsrStatusCode.Unauthenticated:
print("stopTranscribing: Unauthenticated");
break;
case AsrModule.AsrStatusCode.NoInternet:
print("stopTranscribing: No Internet");
break;
}
}
function onTranscriptionUpdate(eventArgs) {
var text = eventArgs.text;
var isFinal = eventArgs.isFinal;
print(`onTranscriptionUpdateCallback text=${text}, isFinal=${isFinal}`)
}
function startSession() {
var options = AsrModule.AsrTranscriptionOptions.create();
options.silenceUntilTerminationMs = 1000;
options.mode = AsrModule.AsrMode.HighAccuracy;
options.onTranscriptionUpdateEvent.add(onTranscriptionUpdateCallback);
options.onTranscriptionErrorEvent.add(onTranscriptionErrorCallback);
// Start session
asrModule.startTranscribing(options);
}
function stopSession() {
asrModule
.stopTranscribing()
.then(function () {
print(
`stopTranscribing successfully`
);
});
}
TypeScript
@component
export class AsrExample extends BaseScriptComponent {
private asrModule = require("LensStudio:AsrModule")
private onTranscriptionUpdate(eventArgs: AsrModule.TranscriptionUpdateEvent) {
print(`onTranscriptionUpdateCallback text=${eventArgs.text}, isFinal=${eventArgs.isFinal}`)
}
private onTranscriptionError(eventArgs: AsrModule.AsrStatusCode) {
print(`onTranscriptionErrorCallback errorCode: ${eventArgs}`);
switch (eventArgs) {
case AsrModule.AsrStatusCode.InternalError:
print("stopTranscribing: Internal Error");
break;
case AsrModule.AsrStatusCode.Unauthenticated:
print("stopTranscribing: Unauthenticated");
break;
case AsrModule.AsrStatusCode.NoInternet:
print("stopTranscribing: No Internet");
break;
}
}
onAwake(): void {
const options = AsrModule.AsrTranscriptionOptions.create()
options.silenceUntilTerminationMs = 1000
options.mode = AsrModule.AsrMode.HighAccuracy
options.onTranscriptionUpdateEvent.add((eventArgs) => this.onTranscriptionUpdate(eventArgs))
options.onTranscriptionErrorEvent.add((eventArgs) => this.onTranscriptionError(eventArgs))
this.asrModule.startTranscribing(options)
}
private stopSession(): void {
this.asrModule.stopTranscribing()
}
}
Extends
Properties
name
name:
string
The name of the Asset in Lens Studio.
Default Value
""
Inherited from
uniqueIdentifier
readonlyuniqueIdentifier:string
Since
Lens Scripting Version 176
Inherited from
Methods
getTypeName()
staticgetTypeName():TypeName<AsrModule>
SPECS
Returns the fully-qualified JavaScript type name for this class (for example, "Component.Camera"). This is a static accessor (no instance required) and returns the same value as the instance getTypeName().
Returns
TypeName<AsrModule>
Since
Lens Scripting Version 309
Overrides
getTypeName()
getTypeName():
string
Returns the name of this object's type.
Returns
string
Inherited from
isOfType()
isOfType(
type):boolean
Returns true if the object matches or derives from the passed in type.
Parameters
| Parameter | Type |
|---|---|
type | string |
Returns
boolean
Inherited from
isSame()
isSame(
other):boolean
Returns true if this object is the same as other. Useful for checking if two references point to the same thing.
Parameters
| Parameter | Type |
|---|---|
other | ScriptObject |
Returns
boolean
Inherited from
startTranscribing()
startTranscribing(
transcriptionOptions):void
Exposes user dataSPECS
Starts a new ASR session. While active the Lens will transcribe speech to text.
Parameters
| Parameter | Type |
|---|---|
transcriptionOptions | AsrTranscriptionOptions |
Returns
void
Remarks
asrTranscriptionOptions provides the options for the session
The event onTranscriptionUpdateEvent is triggered when the transcription is updated.
The event onTranscriptionErrorEvent is triggered when there is an error in the transcription process.
If startTranscribing is called again while a session is active, the current session is cancelled and a new one started.
Since
Lens Scripting Version 309
stopTranscribing()
stopTranscribing(
streamType?):Promise<void>
Exposes user dataSPECS
Stops an active ASR Session before transcription is finished and discards the current session.
Parameters
| Parameter | Type |
|---|---|
streamType? | number |
Returns
Promise<void>
Since
Lens Scripting Version 309
Nested types
Enumerations
| Enumeration | Description |
|---|---|
| AsrContentType | The kind of content the speech is expected to carry. The transcription is processed and formatted accordingly, e.g. to fill in a text field of the matching type. |
| AsrMode | The mode of the transcription to prioritise, between speed and accuracy. |
| AsrStatusCode | An enum stating the status of the transcription. |
Classes
| Class | Description |
|---|---|
| AsrTranscriptionOptions | Provides the options for the session. |
| TranscriptionUpdateEvent | Argument passed for a transcription update event. |