Skip to content

Commit

Permalink
Add transcript message in flow client (#81)
Browse files Browse the repository at this point in the history
Add transcript message. Copy across types from realtime client for now.
  • Loading branch information
TudorCRL authored Nov 6, 2024
1 parent b539c62 commit d04c6b5
Show file tree
Hide file tree
Showing 11 changed files with 1,841 additions and 1,912 deletions.
2 changes: 1 addition & 1 deletion packages/flow-client-react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@speechmatics/flow-client-react",
"version": "0.1.0",
"version": "0.1.1",
"description": "React hooks for interacting with the Speechmatics Flow API",
"main": "dist/index.cjs",
"module": "dist/index.js",
Expand Down
43 changes: 43 additions & 0 deletions packages/flow-client/models/add-transcript.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// NOTE: This file is copied from realtime-client, not auto-generated

import type { RecognitionMetadata } from '../models';
import type { RecognitionResult } from '../models';

/**
*
* @export
* @interface AddTranscript
*/
export interface AddTranscript {
/**
*
* @type {string}
* @memberof AddTranscript
*/
message: AddTranscriptMessageEnum;
/**
* Speechmatics JSON output format version number.
* @type {string}
* @memberof AddTranscript
*/
format?: string;
/**
*
* @type {RecognitionMetadata}
* @memberof AddTranscript
*/
metadata: RecognitionMetadata;
/**
*
* @type {Array<RecognitionResult>}
* @memberof AddTranscript
*/
results: Array<RecognitionResult>;
}

export const AddTranscriptMessageEnum = {
AddTranscript: 'AddTranscript',
} as const;

export type AddTranscriptMessageEnum =
(typeof AddTranscriptMessageEnum)[keyof typeof AddTranscriptMessageEnum];
5 changes: 5 additions & 0 deletions packages/flow-client/models/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export * from './add-transcript';
export * from './recognition-alternative';
export * from './recognition-result';
export * from './recognition-metadata';
export * from './recognition-display';
41 changes: 41 additions & 0 deletions packages/flow-client/models/recognition-alternative.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// NOTE: This file is copied from realtime-client, not auto-generated

import type { RecognitionDisplay } from '../models';

/**
*
* @export
* @interface RecognitionAlternative
*/
export interface RecognitionAlternative {
/**
*
* @type {string}
* @memberof RecognitionAlternative
*/
content: string;
/**
*
* @type {number}
* @memberof RecognitionAlternative
*/
confidence: number;
/**
*
* @type {string}
* @memberof RecognitionAlternative
*/
language?: string;
/**
*
* @type {RecognitionDisplay}
* @memberof RecognitionAlternative
*/
display?: RecognitionDisplay;
/**
*
* @type {string}
* @memberof RecognitionAlternative
*/
speaker?: string;
}
23 changes: 23 additions & 0 deletions packages/flow-client/models/recognition-display.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// NOTE: This file is copied from realtime-client, not auto-generated

/**
*
* @export
* @interface RecognitionDisplay
*/
export interface RecognitionDisplay {
/**
*
* @type {string}
* @memberof RecognitionDisplay
*/
direction: RecognitionDisplayDirectionEnum;
}

export const RecognitionDisplayDirectionEnum = {
Ltr: 'ltr',
Rtl: 'rtl',
} as const;

export type RecognitionDisplayDirectionEnum =
(typeof RecognitionDisplayDirectionEnum)[keyof typeof RecognitionDisplayDirectionEnum];
27 changes: 27 additions & 0 deletions packages/flow-client/models/recognition-metadata.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// NOTE: This file is copied from realtime-client, not auto-generated

/**
*
* @export
* @interface RecognitionMetadata
*/
export interface RecognitionMetadata {
/**
*
* @type {number}
* @memberof RecognitionMetadata
*/
start_time: number;
/**
*
* @type {number}
* @memberof RecognitionMetadata
*/
end_time: number;
/**
*
* @type {string}
* @memberof RecognitionMetadata
*/
transcript: string;
}
82 changes: 82 additions & 0 deletions packages/flow-client/models/recognition-result.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// NOTE: This file is copied from realtime-client, not auto-generated

import type { RecognitionAlternative } from './recognition-alternative';

/**
*
* @export
* @interface RecognitionResult
*/
export interface RecognitionResult {
/**
*
* @type {string}
* @memberof RecognitionResult
*/
type: RecognitionResultTypeEnum;
/**
*
* @type {number}
* @memberof RecognitionResult
*/
start_time: number;
/**
*
* @type {number}
* @memberof RecognitionResult
*/
end_time: number;
/**
*
* @type {string}
* @memberof RecognitionResult
*/
channel?: string;
/**
*
* @type {string}
* @memberof RecognitionResult
*/
attaches_to?: RecognitionResultAttachesToEnum;
/**
*
* @type {boolean}
* @memberof RecognitionResult
*/
is_eos?: boolean;
/**
*
* @type {Array<RecognitionAlternative>}
* @memberof RecognitionResult
*/
alternatives?: Array<RecognitionAlternative>;
/**
*
* @type {number}
* @memberof RecognitionResult
*/
score?: number;
/**
*
* @type {number}
* @memberof RecognitionResult
*/
volume?: number;
}

export const RecognitionResultTypeEnum = {
Word: 'word',
Punctuation: 'punctuation',
} as const;

export type RecognitionResultTypeEnum =
(typeof RecognitionResultTypeEnum)[keyof typeof RecognitionResultTypeEnum];
export const RecognitionResultAttachesToEnum = {
Next: 'next',
Previous: 'previous',
None: 'none',
Both: 'both',
} as const;

export type RecognitionResultAttachesToEnum =
(typeof RecognitionResultAttachesToEnum)[keyof typeof RecognitionResultAttachesToEnum];
2 changes: 1 addition & 1 deletion packages/flow-client/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@speechmatics/flow-client",
"version": "0.1.0",
"version": "0.1.1",
"description": "",
"main": "dist/index.js",
"files": ["dist/", "README.md"],
Expand Down
8 changes: 8 additions & 0 deletions packages/flow-client/src/events.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//////////////////////////////////////////////
// Incoming messages: server -> client
//////////////////////////////////////////////
import { RecognitionResult, RecognitionMetadata } from '../models';

export type ConversationStartedMessage = {
message: 'ConversationStarted';
Expand Down Expand Up @@ -33,6 +34,12 @@ export type ResponseCompletedMessage = {
end_time: number;
};

export type AddTranscriptMessage = {
message: 'AddTranscript';
results: Array<RecognitionResult>;
metadata: RecognitionMetadata;
};

export type ResponseInterruptedMessage = {
message: 'ResponseInterrupted';
content: string;
Expand Down Expand Up @@ -69,6 +76,7 @@ export type FlowClientIncomingMessage =
| ResponseStartedMessage
| ResponseCompletedMessage
| ResponseInterruptedMessage
| AddTranscriptMessage
| ConversationEndingMessage
| ConversationEndedMessage
| InfoMessage
Expand Down
1 change: 1 addition & 0 deletions packages/flow-client/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './client';
export * from './events';
export * from './personas';
export * from '../models';
Loading

0 comments on commit d04c6b5

Please sign in to comment.