Skip to main content

AsrModule

Class

Allows 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

Platform details

  • Snapchat — Not supported — Available on SPECS only.

  • SPECS — Fully supported.

  • Camera Kit Web — Not supported — Available on SPECS only.

  • Camera Kit Mobile — Not 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

Asset.name


uniqueIdentifier

readonly uniqueIdentifier: string

Since

Lens Scripting Version 176

Inherited from

Asset.uniqueIdentifier

Methods

getTypeName()

static getTypeName(): 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

Asset.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Asset.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object matches or derives from the passed in type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Asset.isOfType


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

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Asset.isSame


startTranscribing()

startTranscribing(transcriptionOptions): void

Exposes user dataSPECS

Starts a new ASR session. While active the Lens will transcribe speech to text.

Parameters

ParameterType
transcriptionOptionsAsrTranscriptionOptions

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

ParameterType
streamType?number

Returns

Promise<void>

Since

Lens Scripting Version 309

Nested types

Enumerations

EnumerationDescription
AsrContentTypeThe 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.
AsrModeThe mode of the transcription to prioritise, between speed and accuracy.
AsrStatusCodeAn enum stating the status of the transcription.

Classes

ClassDescription
AsrTranscriptionOptionsProvides the options for the session.
TranscriptionUpdateEventArgument passed for a transcription update event.