UNPKG

@speechmatics/real-time-client

Version:

Client for the Speechmatics real-time API

448 lines (406 loc) 16.3 kB
import { TypedEventTarget } from 'typescript-event-target'; interface AudioEventsConfig { types?: Array<string>; } interface AudioFormatFile { type: AudioFormatFileTypeEnum; } declare const AudioFormatFileTypeEnum: { readonly File: "file"; }; type AudioFormatFileTypeEnum = (typeof AudioFormatFileTypeEnum)[keyof typeof AudioFormatFileTypeEnum]; interface AudioFormatRaw { type: AudioFormatRawTypeEnum; encoding: AudioFormatRawEncodingEnum; sample_rate: number; } declare const AudioFormatRawTypeEnum: { readonly Raw: "raw"; }; type AudioFormatRawTypeEnum = (typeof AudioFormatRawTypeEnum)[keyof typeof AudioFormatRawTypeEnum]; declare const AudioFormatRawEncodingEnum: { readonly PcmF32le: "pcm_f32le"; readonly PcmS16le: "pcm_s16le"; readonly Mulaw: "mulaw"; }; type AudioFormatRawEncodingEnum = (typeof AudioFormatRawEncodingEnum)[keyof typeof AudioFormatRawEncodingEnum]; type AudioFormat = AudioFormatFile | AudioFormatRaw; interface AudioFilteringConfig { volume_threshold?: number; } declare const DiarizationConfig: { readonly None: "none"; readonly Speaker: "speaker"; }; type DiarizationConfig = (typeof DiarizationConfig)[keyof typeof DiarizationConfig]; declare const MaxDelayModeConfig: { readonly Flexible: "flexible"; readonly Fixed: "fixed"; }; type MaxDelayModeConfig = (typeof MaxDelayModeConfig)[keyof typeof MaxDelayModeConfig]; declare const OperatingPoint: { readonly Standard: "standard"; readonly Enhanced: "enhanced"; }; type OperatingPoint = (typeof OperatingPoint)[keyof typeof OperatingPoint]; interface PunctuationOverrides { permitted_marks?: Array<string>; sensitivity?: number; } interface SpeakerDiarizationConfig { max_speakers?: number; } interface TranscriptFilteringConfig { remove_disfluencies?: boolean; } interface VocabWordOneOf { content: string; sounds_like?: Array<string>; } type VocabWord = VocabWordOneOf | string; interface TranscriptionConfig { language: string; domain?: string; output_locale?: string; additional_vocab?: Array<VocabWord>; diarization?: DiarizationConfig; max_delay?: number; max_delay_mode?: MaxDelayModeConfig; speaker_diarization_config?: SpeakerDiarizationConfig; audio_filtering_config?: AudioFilteringConfig; transcript_filtering_config?: TranscriptFilteringConfig; enable_partials?: boolean; enable_entities?: boolean; operating_point?: OperatingPoint; punctuation_overrides?: PunctuationOverrides; } interface TranslationConfig { target_languages: Array<string>; enable_partials?: boolean; } interface StartRecognition { message: StartRecognitionMessageEnum; audio_format: AudioFormat; transcription_config: TranscriptionConfig; translation_config?: TranslationConfig; audio_events_config?: AudioEventsConfig; } declare const StartRecognitionMessageEnum: { readonly StartRecognition: "StartRecognition"; }; type StartRecognitionMessageEnum = (typeof StartRecognitionMessageEnum)[keyof typeof StartRecognitionMessageEnum]; interface SetRecognitionConfig { message: SetRecognitionConfigMessageEnum; transcription_config: TranscriptionConfig; } declare const SetRecognitionConfigMessageEnum: { readonly SetRecognitionConfig: "SetRecognitionConfig"; }; type SetRecognitionConfigMessageEnum = (typeof SetRecognitionConfigMessageEnum)[keyof typeof SetRecognitionConfigMessageEnum]; interface EndOfStream { message: EndOfStreamMessageEnum; last_seq_no: number; } declare const EndOfStreamMessageEnum: { readonly EndOfStream: "EndOfStream"; }; type EndOfStreamMessageEnum = (typeof EndOfStreamMessageEnum)[keyof typeof EndOfStreamMessageEnum]; interface RecognitionStarted { message: RecognitionStartedMessageEnum; id?: string; } declare const RecognitionStartedMessageEnum: { readonly RecognitionStarted: "RecognitionStarted"; }; type RecognitionStartedMessageEnum = (typeof RecognitionStartedMessageEnum)[keyof typeof RecognitionStartedMessageEnum]; interface AudioAdded { message: AudioAddedMessageEnum; seq_no: number; } declare const AudioAddedMessageEnum: { readonly AudioAdded: "AudioAdded"; }; type AudioAddedMessageEnum = (typeof AudioAddedMessageEnum)[keyof typeof AudioAddedMessageEnum]; interface RecognitionMetadata { start_time: number; end_time: number; transcript: string; } interface RecognitionDisplay { direction: RecognitionDisplayDirectionEnum; } declare const RecognitionDisplayDirectionEnum: { readonly Ltr: "ltr"; readonly Rtl: "rtl"; }; type RecognitionDisplayDirectionEnum = (typeof RecognitionDisplayDirectionEnum)[keyof typeof RecognitionDisplayDirectionEnum]; interface RecognitionAlternative { content: string; confidence: number; language?: string; display?: RecognitionDisplay; speaker?: string; } interface RecognitionResult { type: RecognitionResultTypeEnum; start_time: number; end_time: number; channel?: string; attaches_to?: RecognitionResultAttachesToEnum; is_eos?: boolean; alternatives?: Array<RecognitionAlternative>; score?: number; volume?: number; } declare const RecognitionResultTypeEnum: { readonly Word: "word"; readonly Punctuation: "punctuation"; }; type RecognitionResultTypeEnum = (typeof RecognitionResultTypeEnum)[keyof typeof RecognitionResultTypeEnum]; declare const RecognitionResultAttachesToEnum: { readonly Next: "next"; readonly Previous: "previous"; readonly None: "none"; readonly Both: "both"; }; type RecognitionResultAttachesToEnum = (typeof RecognitionResultAttachesToEnum)[keyof typeof RecognitionResultAttachesToEnum]; interface AddPartialTranscript { message: AddPartialTranscriptMessageEnum; format?: string; metadata: RecognitionMetadata; results: Array<RecognitionResult>; } declare const AddPartialTranscriptMessageEnum: { readonly AddPartialTranscript: "AddPartialTranscript"; }; type AddPartialTranscriptMessageEnum = (typeof AddPartialTranscriptMessageEnum)[keyof typeof AddPartialTranscriptMessageEnum]; interface AddTranscript { message: AddTranscriptMessageEnum; format?: string; metadata: RecognitionMetadata; results: Array<RecognitionResult>; } declare const AddTranscriptMessageEnum: { readonly AddTranscript: "AddTranscript"; }; type AddTranscriptMessageEnum = (typeof AddTranscriptMessageEnum)[keyof typeof AddTranscriptMessageEnum]; interface TranslatedSentence { content: string; start_time: number; end_time: number; speaker?: string; } interface AddPartialTranslation { message: AddPartialTranslationMessageEnum; format?: string; language: string; results: Array<TranslatedSentence>; } declare const AddPartialTranslationMessageEnum: { readonly AddPartialTranslation: "AddPartialTranslation"; }; type AddPartialTranslationMessageEnum = (typeof AddPartialTranslationMessageEnum)[keyof typeof AddPartialTranslationMessageEnum]; interface AddTranslation { message: AddTranslationMessageEnum; format?: string; language: string; results: Array<TranslatedSentence>; } declare const AddTranslationMessageEnum: { readonly AddTranslation: "AddTranslation"; }; type AddTranslationMessageEnum = (typeof AddTranslationMessageEnum)[keyof typeof AddTranslationMessageEnum]; interface EndOfTranscript { message: EndOfTranscriptMessageEnum; } declare const EndOfTranscriptMessageEnum: { readonly EndOfTranscript: "EndOfTranscript"; }; type EndOfTranscriptMessageEnum = (typeof EndOfTranscriptMessageEnum)[keyof typeof EndOfTranscriptMessageEnum]; interface AudioEventStartedEvent { type: string; start_time: number; confidence: number; } interface AudioEventStarted { message: AudioEventStartedMessageEnum; event: AudioEventStartedEvent; } declare const AudioEventStartedMessageEnum: { readonly AudioEventStarted: "AudioEventStarted"; }; type AudioEventStartedMessageEnum = (typeof AudioEventStartedMessageEnum)[keyof typeof AudioEventStartedMessageEnum]; interface AudioEventEndedEvent { type: string; end_time: number; } interface AudioEventEnded { message: AudioEventEndedMessageEnum; event: AudioEventEndedEvent; } declare const AudioEventEndedMessageEnum: { readonly AudioEventEnded: "AudioEventEnded"; }; type AudioEventEndedMessageEnum = (typeof AudioEventEndedMessageEnum)[keyof typeof AudioEventEndedMessageEnum]; interface Info { message: InfoMessageEnum; type: InfoTypeEnum; reason: string; code?: number; seq_no?: number; quality?: string; usage?: number; quota?: number; } declare const InfoMessageEnum: { readonly Info: "Info"; }; type InfoMessageEnum = (typeof InfoMessageEnum)[keyof typeof InfoMessageEnum]; declare const InfoTypeEnum: { readonly RecognitionQuality: "recognition_quality"; readonly ModelRedirect: "model_redirect"; readonly Deprecated: "deprecated"; readonly ConcurrentSessionUsage: "concurrent_session_usage"; }; type InfoTypeEnum = (typeof InfoTypeEnum)[keyof typeof InfoTypeEnum]; interface Warning { message: WarningMessageEnum; type: WarningTypeEnum; reason: string; code?: number; seq_no?: number; duration_limit?: number; } declare const WarningMessageEnum: { readonly Warning: "Warning"; }; type WarningMessageEnum = (typeof WarningMessageEnum)[keyof typeof WarningMessageEnum]; declare const WarningTypeEnum: { readonly DurationLimitExceeded: "duration_limit_exceeded"; }; type WarningTypeEnum = (typeof WarningTypeEnum)[keyof typeof WarningTypeEnum]; interface ModelError { message: ModelErrorMessageEnum; type: ModelErrorTypeEnum; reason: string; code?: number; seq_no?: number; } declare const ModelErrorMessageEnum: { readonly Error: "Error"; }; type ModelErrorMessageEnum = (typeof ModelErrorMessageEnum)[keyof typeof ModelErrorMessageEnum]; declare const ModelErrorTypeEnum: { readonly InvalidMessage: "invalid_message"; readonly InvalidModel: "invalid_model"; readonly InvalidConfig: "invalid_config"; readonly InvalidAudioType: "invalid_audio_type"; readonly NotAuthorised: "not_authorised"; readonly InsufficientFunds: "insufficient_funds"; readonly NotAllowed: "not_allowed"; readonly JobError: "job_error"; readonly DataError: "data_error"; readonly BufferError: "buffer_error"; readonly ProtocolError: "protocol_error"; readonly TimelimitExceeded: "timelimit_exceeded"; readonly QuotaExceeded: "quota_exceeded"; readonly UnknownError: "unknown_error"; }; type ModelErrorTypeEnum = (typeof ModelErrorTypeEnum)[keyof typeof ModelErrorTypeEnum]; type RealtimeClientMessage = StartRecognition | { message: 'AddAudio'; } | SetRecognitionConfig | EndOfStream; type RealtimeServerMessage = SetRecognitionConfig | RecognitionStarted | AudioAdded | AddPartialTranscript | AddTranscript | AddPartialTranslation | AddTranslation | EndOfTranscript | AudioEventStarted | AudioEventEnded | Info | Warning | ModelError; declare class SocketStateChangeEvent extends Event { readonly socketState: RealtimeClient['socketState']; constructor(socketState: RealtimeClient['socketState']); } declare class ReceiveMessageEvent extends Event { readonly data: RealtimeServerMessage; constructor(data: RealtimeServerMessage); } declare class SendMessageEvent extends Event { readonly data: RealtimeClientMessage; constructor(data: RealtimeClientMessage); } interface RealtimeClientEventMap { sendMessage: SendMessageEvent; receiveMessage: ReceiveMessageEvent; socketStateChange: SocketStateChangeEvent; } interface RealtimeClientOptions { url?: string; appId?: string; enableLegacy?: boolean; } type RealtimeTranscriptionConfig = Omit<StartRecognition, 'message' | 'audio_format'> & Partial<Pick<StartRecognition, 'audio_format'>>; declare class RealtimeClient extends TypedEventTarget<RealtimeClientEventMap> { constructor(config?: RealtimeClientOptions); readonly url: string; private readonly appId?; private readonly enableLegacy; private socket?; get socketState(): "connecting" | "open" | "closing" | "closed" | undefined; private lastAudioAddedSeqNo; private connect; sendMessage(message: RealtimeClientMessage): void; sendAudio(data: Blob | ArrayBufferLike | string): void; start(jwt: string, config: RealtimeTranscriptionConfig): Promise<RecognitionStarted>; stopRecognition({ noTimeout }?: { noTimeout?: true; }): Promise<unknown>; } declare class SpeechmaticsRealtimeError extends Error { constructor(message: string, options?: ErrorOptions); } interface RealtimeMessage { message?: RealtimeMessageMessageEnum; } declare const RealtimeMessageMessageEnum: { readonly StartRecognition: "StartRecognition"; readonly AddAudio: "AddAudio"; readonly EndOfStream: "EndOfStream"; readonly SetRecognitionConfig: "SetRecognitionConfig"; readonly RecognitionStarted: "RecognitionStarted"; readonly AudioAdded: "AudioAdded"; readonly AddPartialTranscript: "AddPartialTranscript"; readonly AddTranscript: "AddTranscript"; readonly AddPartialTranslation: "AddPartialTranslation"; readonly AddTranslation: "AddTranslation"; readonly EndOfTranscript: "EndOfTranscript"; readonly AudioEventStarted: "AudioEventStarted"; readonly AudioEventEnded: "AudioEventEnded"; readonly Info: "Info"; readonly Warning: "Warning"; readonly Error: "Error"; }; type RealtimeMessageMessageEnum = (typeof RealtimeMessageMessageEnum)[keyof typeof RealtimeMessageMessageEnum]; declare function getFeatures(region?: Region): Promise<FeatureResponse>; type Region = 'eu2' | 'neu' | 'wus'; interface FeatureResponse { metadata: { language_pack_info: Record<string, { language_description: string; locales?: Record<string, { name: string; }>; }>; }; realtime: { transcription: [ { version: 'latest'; languages: string[]; locales: Record<string, string[]>; domains: Record<string, string[]>; } ]; translation: [ { version: 'latest'; languages: Record<string, string[]>; } ]; }; } export { type AddPartialTranscript, AddPartialTranscriptMessageEnum, type AddPartialTranslation, AddPartialTranslationMessageEnum, type AddTranscript, AddTranscriptMessageEnum, type AddTranslation, AddTranslationMessageEnum, type AudioAdded, AudioAddedMessageEnum, type AudioEventEnded, type AudioEventEndedEvent, AudioEventEndedMessageEnum, type AudioEventStarted, type AudioEventStartedEvent, AudioEventStartedMessageEnum, type AudioEventsConfig, type AudioFilteringConfig, type AudioFormat, type AudioFormatFile, AudioFormatFileTypeEnum, type AudioFormatRaw, AudioFormatRawEncodingEnum, AudioFormatRawTypeEnum, DiarizationConfig, type EndOfStream, EndOfStreamMessageEnum, type EndOfTranscript, EndOfTranscriptMessageEnum, type FeatureResponse, type Info, InfoMessageEnum, InfoTypeEnum, MaxDelayModeConfig, type ModelError, ModelErrorMessageEnum, ModelErrorTypeEnum, OperatingPoint, type PunctuationOverrides, RealtimeClient, type RealtimeClientEventMap, type RealtimeClientMessage, type RealtimeClientOptions, type RealtimeMessage, RealtimeMessageMessageEnum, type RealtimeServerMessage, type RealtimeTranscriptionConfig, ReceiveMessageEvent, type RecognitionAlternative, type RecognitionDisplay, RecognitionDisplayDirectionEnum, type RecognitionMetadata, type RecognitionResult, RecognitionResultAttachesToEnum, RecognitionResultTypeEnum, type RecognitionStarted, RecognitionStartedMessageEnum, SendMessageEvent, type SetRecognitionConfig, SetRecognitionConfigMessageEnum, SocketStateChangeEvent, type SpeakerDiarizationConfig, SpeechmaticsRealtimeError, type StartRecognition, StartRecognitionMessageEnum, type TranscriptFilteringConfig, type TranscriptionConfig, type TranslatedSentence, type TranslationConfig, type VocabWord, type VocabWordOneOf, type Warning, WarningMessageEnum, WarningTypeEnum, getFeatures };