Octopus - Web API
API Reference for the Octopus Web SDK.
Octopus
class Octopus implements OctopusEngine
Class for Octopus Speech-to-Index engine.
Octopus.create()
static async function create(accessKey: string): Promise<Octopus>
Creates an instance of Octopus Speech-to-Index engine.
Parameters
accessKey
string : AccessKey obtained from Picovoice Console.
Returns
Octopus
: An instance of Octopus Speech-to-Index engine.
Octopus.index()
async function index(pcm: Int16Array): Promise<OctopusMetadata>
Processes multiple frames of audio samples. The required sample rate can be retrieved from 'sampleRate'. The audio must be single-channel and 16-bit linearly-encoded.
Parameters
pcm
Int16Array : Audio data.
Returns
OctopusMetadata
: Octopus metadata object.
Octopus.search()
async function search(octopusMetadata: OctopusMetadata, searchPhrase: string): Promise<OctopusMatch[]> {
Searches metadata for a given search phrase.
Parameters
octopusMetadata
OctopusMetadata : An octopus metadata object (indexed audio).searchPhrase
string : The text phrase to search for.
Returns
OctopusMatch[]
: An array of OctopusMatch objects.
Octopus.release()
async function release(): Promise<void>
Releases resources acquired by the Octopus Speech-to-Index engine.
Octopus.sampleRate
get sampleRate(): number
Audio sample rate accepted by Octopus.
Octopus.version
get version(): string
Octopus version string.
OctopusMatch
export type OctopusMatch = {startSec: number;endSec: number;probability: number;};
Type which contains a search result from a call to .search()
.
startSec
number : Start of the matched audio in seconds (Float32).endSec
number : End of the matched audio in seconds (Float32).probability
number : Probability (confidence) that this matches the search phrase. (Float32 in range [0, 1]).
OctopusWorker
export interface OctopusWorker extends Omit<Worker, 'postMessage'>
Interface for the Octopus web worker.
OctopusWorkerFactory
class OctopusWorkerFactory
A factory class for creating new instances of the OctopusWorker
web worker.
OctopusWorkerFactory.create()
static async function create(accessKey: string,indexCallback?: (metadata: OctopusMetadata) => void,searchCallback?: (matches: OctopusMatch[]) => void,errorCallback?: (error: string | Error) => void,): Promise<OctopusWorker>
Creates Octopus web worker instances. The promise resolves when the worker is ready to index voice data.
Parameters
accessKey
string : AccessKey obtained from Picovoice ConsoleindexCallback
(OctopusMetadata) => void : (Optional) Callback invoked once the Octopus worker has finished indexing audio.searchCallback
(OctopusMatch[]) => void : (Optional) Callback invoked once the Octopus worker has completed a search.errorCallback
(string | Error) => void : (Optional) Callback invoked on an error.
Returns
OctopusWorker
: An Octopus web worker.