From e83c6d1ee9ef3d603093b832d288c205efe7dac4 Mon Sep 17 00:00:00 2001 From: Michael Jolley Date: Wed, 14 Jul 2021 17:07:19 -0500 Subject: [PATCH] Adding utterances and modifying property names --- CHANGELOG.md | 47 +++++- README.md | 159 ++++++++++++------ package.json | 4 +- sample/index.js | 13 +- src/httpRequest.ts | 1 + src/projects.ts | 15 +- src/types/index.ts | 2 + src/types/key.ts | 4 +- src/types/prerecordedTranscriptionResponse.ts | 2 + src/types/project.ts | 8 +- src/types/projectPatchResponse.ts | 6 + src/types/usageRequest.ts | 2 +- src/types/utterance.ts | 39 +++++ tests/mockResults.ts | 2 +- 14 files changed, 238 insertions(+), 66 deletions(-) create mode 100644 src/types/projectPatchResponse.ts create mode 100644 src/types/utterance.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 97fb7be8..6abf5667 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,50 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --- +## [1.0.2] + +### Added + +- `deepgram.projects.update` will now update a project +- Prerecorded transcription responses now include utterances + +### Updated + +- The project type has been modified to the following: + +```ts +{ + project_id: string; + name?: string; + company?: string; +}; +``` + +- The key type has been modified to the following: + +```ts +{ + api_key_id: string; + key?: string; + comment: string; + created: string; + scopes: Array; +}; +``` + +- The usage request type has been modified to the following: + +```ts +{ + request_id: string; + created: string; + path: string; + accessor: string; + response?: UsageRequestDetail | UsageRequestMessage; + callback?: UsageCallback; +}; +``` + ## [1.0.0] ### Added @@ -52,7 +96,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --- -[unreleased]: https://github.com/deepgram/node-sdk/compare/1.0.0...HEAD +[unreleased]: https://github.com/deepgram/node-sdk/compare/1.0.2...HEAD +[1.0.2]: https://github.com/deepgram/node-sdk/compare/1.0.0...1.0.2 [1.0.0]: https://github.com/deepgram/node-sdk/compare/0.6.5...1.0.0 [0.6.5]: https://github.com/deepgram/node-sdk/compare/0.6.4...0.6.5 [0.6.4]: https://github.com/deepgram/node-sdk/compare/edc07b4...0.6.4 diff --git a/README.md b/README.md index 82124b88..9761dd0c 100644 --- a/README.md +++ b/README.md @@ -194,6 +194,62 @@ Additional transcription options can be provided for prerecorded transcriptions. } ``` +#### Prerecorded Transcription Response + +```ts +{ + request_id?: string; + metadata?: { + request_id: string; + transaction_key: string; + sha256: string; + created: string; + duration: number; + channels: number; + }; + results?: { + channels: Array<{ + search?: Array<{ + query: string; + hits: Array<{ + confidence: number; + start: number; + end: number; + snippet: string; + }>; + }>; + alternatives: Array<{ + transcript: string; + confidence: number; + words: Array<{ + word: string; + start: number; + end: number; + confidence: number; + punctuated_word?: string; + }>; + }>; + }>; + utterances?: Array<{ + start: number; + end: number; + confidence: number; + channel: number; + transcript: string; + words: Array<{ + word: string; + start: number; + end: number; + confidence: number; + punctuated_word?: string; + }>; + speaker?: number; + id: string; + }>; + }; +}; +``` + ### Live Transcription The `transcription.live` method provides access to a websocket connection @@ -378,52 +434,38 @@ Additional transcription options can be provided for live transcriptions. } ``` -### Transcription Response +#### Live Transcription Response -```js +```ts { - "metadata": { - "request_id": "string", - "transaction_key": "string", - "sha256": "string", - "created": "string", - "duration": 0, - "channels": 0 - }, - "results": { - "channels": [ - { - "search": [ - { - "query": "string", - "hits": [ - { - "confidence": 0, - "start": 0, - "end": 0, - "snippet": "string" - } - ] - } - ], - "alternatives": [ - { - "transcript": "string", - "confidence": 0, - "words": [ - { - "word": "string", - "start": 0, - "end": 0, - "confidence": 0 - } - ] - } - ] - } - ] + channel_index: Array; + duration: number; + start: number; + is_final: boolean; + speech_final: boolean; + channel: { + search?: Array<{ + query: string; + hits: Array<{ + confidence: number; + start: number; + end: number; + snippet: string; + }> + }>, + alternatives: Array<{ + transcript: string; + confidence: number; + words: Array<{ + word: string; + start: number; + end: number; + confidence: number; + punctuated_word?: string; + }> + }> } -} +}; ``` ## Project Management @@ -466,6 +508,23 @@ const project = await deepgram.projects.get(PROJECT_ID); } ``` +### Update a Project + +Updates a project based on a provided project object. This object must contain +`project_id` and `name` properties. + +```js +const updateResponse = await deepgram.projects.update(project); +``` + +#### Update a Project Response + +```ts +{ + message: string; +} +``` + ## Key Management ### List Keys @@ -480,11 +539,11 @@ const response = await deepgram.keys.list(PROJECT_ID); ```ts { - keys: [ + api_keys: [ { - id: string, + api_key_id: string, comment: string, - created: Date, + created: string, scopes: Array }, ]; @@ -504,10 +563,10 @@ const response = await deepgram.keys.create(PROJECT_ID, COMMENT_FOR_KEY); ```ts { - id: string, + api_key_id: string, key: string, comment: string, - created: Date, + created: string, scopes: Array } ``` @@ -564,7 +623,7 @@ const response = await deepgram.usage.listRequests(PROJECT_ID, { limit: number, requests?: [ { - id: string; + request_id: string; created: string; path: string; accessor: string; @@ -623,7 +682,7 @@ const response = await deepgram.usage.getRequest(PROJECT_ID, REQUEST_ID); ```ts { - id: string; + request_id: string; created: string; path: string; accessor: string; diff --git a/package.json b/package.json index 79d17f65..10ab7638 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@deepgram/sdk", - "version": "1.0.1", + "version": "1.0.2", "description": "An SDK for the Deepgram automated speech recognition platform", "main": "dist/index.js", "types": "dist/index.d.ts", @@ -54,4 +54,4 @@ "dependencies": { "ws": "^7.4.6" } -} +} \ No newline at end of file diff --git a/sample/index.js b/sample/index.js index b374830e..14d72f38 100644 --- a/sample/index.js +++ b/sample/index.js @@ -21,8 +21,8 @@ function main() { const project = projects.projects[0]; /** Create an API key in the project */ - const apiKey = await deepgram.keys.create(project.id, "test key", ['member']); - console.log(`Key created: ${apiKey.id}`); + const apiKey = await deepgram.keys.create(project.project_id, "test key", ['member']); + console.log(`Key created: ${apiKey.api_key_id}`); const newDeepgram = new Deepgram(apiKey.key); @@ -30,16 +30,17 @@ function main() { const transcription = await newDeepgram.transcription.preRecorded({ url: config.urlToFile }, { - punctuate: true + punctuate: true, + utterances: true }); console.dir(transcription, { depth: null }); /** Retrieve & log usage for this project */ - const usage = await newDeepgram.usage.listRequests(project.id); + const usage = await newDeepgram.usage.listRequests(project.project_id); console.dir(usage, { depth: null }); - await deepgram.keys.delete(project.id, apiKey.id); - console.log(`Key deleted: ${apiKey.id}`); + await deepgram.keys.delete(project.project_id, apiKey.api_key_id); + console.log(`Key deleted: ${apiKey.api_key_id}`); resolve(); } diff --git a/src/httpRequest.ts b/src/httpRequest.ts index 5ca05bd1..d6417f5d 100644 --- a/src/httpRequest.ts +++ b/src/httpRequest.ts @@ -61,6 +61,7 @@ export function _request( dgRes.on("end", () => { let dgResponse; try { + console.log(`content: ${dgResContent}`); dgResponse = JSON.parse(dgResContent); } catch (err) { dgResponse = { error: dgResContent }; diff --git a/src/projects.ts b/src/projects.ts index 6c678cf5..82827118 100644 --- a/src/projects.ts +++ b/src/projects.ts @@ -1,5 +1,5 @@ import { _request } from "./httpRequest"; -import { Project, ProjectResponse } from "./types"; +import { Project, ProjectPatchResponse, ProjectResponse } from "./types"; export class Projects { constructor(private _credentials: string, private _apiUrl: string) {} @@ -30,4 +30,17 @@ export class Projects { `${this.apiPath}/${projectId}` ); } + + /** + * Update a specific project + * @param project project to update + */ + async update(project: Project): Promise { + return _request( + "PATCH", + this._credentials, + this._apiUrl, + `${this.apiPath}/${project.project_id}` + ); + } } diff --git a/src/types/index.ts b/src/types/index.ts index e73a874b..c7c3ad8b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -9,6 +9,7 @@ export * from "./metadata"; export * from "./prerecordedTranscriptionOptions"; export * from "./prerecordedTranscriptionResponse"; export * from "./project"; +export * from "./projectPatchResponse"; export * from "./projectResponse"; export * from "./search"; export * from "./transcriptionSource"; @@ -22,4 +23,5 @@ export * from "./usageRequestList"; export * from "./usageRequestListOptions"; export * from "./usageResponse"; export * from "./usageResponseDetail"; +export * from "./utterance"; export * from "./wordBase"; diff --git a/src/types/key.ts b/src/types/key.ts index 3b0e35ee..4ab6f781 100644 --- a/src/types/key.ts +++ b/src/types/key.ts @@ -5,7 +5,7 @@ export type Key = { /** * Unique identifier of the key to use in API requests */ - id: string; + api_key_id: string; /** * API key to send in API requests (Only displayed when first created) */ @@ -17,7 +17,7 @@ export type Key = { /** * Timestamp of the date/time the key was created */ - created: Date; + created: string; /** * Array of scopes assigned to the key */ diff --git a/src/types/prerecordedTranscriptionResponse.ts b/src/types/prerecordedTranscriptionResponse.ts index 8972f4c8..4df34681 100644 --- a/src/types/prerecordedTranscriptionResponse.ts +++ b/src/types/prerecordedTranscriptionResponse.ts @@ -1,10 +1,12 @@ import { Metadata } from "./metadata"; import { Channel } from "./channel"; +import { Utterance } from "./utterance"; export type PrerecordedTranscriptionResponse = { request_id?: string; metadata?: Metadata; results?: { channels: Array; + utterances?: Array; }; }; diff --git a/src/types/project.ts b/src/types/project.ts index 47a9bbe2..404b416e 100644 --- a/src/types/project.ts +++ b/src/types/project.ts @@ -5,9 +5,13 @@ export type Project = { /** * Unique identifier of the project */ - id: string; + project_id: string; /** * User provided name of the project */ - name: string; + name?: string; + /** + * Name of the company associated with the project. Optional. + */ + company?: string; }; diff --git a/src/types/projectPatchResponse.ts b/src/types/projectPatchResponse.ts new file mode 100644 index 00000000..bb7838f0 --- /dev/null +++ b/src/types/projectPatchResponse.ts @@ -0,0 +1,6 @@ +export type ProjectPatchResponse = { + /** + * Success message. + */ + message: string; +}; diff --git a/src/types/usageRequest.ts b/src/types/usageRequest.ts index 3082a340..3979e1c7 100644 --- a/src/types/usageRequest.ts +++ b/src/types/usageRequest.ts @@ -3,7 +3,7 @@ import { UsageRequestDetail } from "./usageRequestDetail"; import { UsageRequestMessage } from "./usageRequestMessage"; export type UsageRequest = { - id: string; + request_id: string; created: string; path: string; accessor: string; diff --git a/src/types/utterance.ts b/src/types/utterance.ts new file mode 100644 index 00000000..5568209f --- /dev/null +++ b/src/types/utterance.ts @@ -0,0 +1,39 @@ +import { WordBase } from "./wordBase"; + +export type Utterance = { + /** + * Start time (in seconds) from the beginning of the audio stream. + */ + start: number; + /** + * End time (in seconds) from the beginning of the audio stream. + */ + end: number; + /** + * Floating point value between 0 and 1 that indicates overall transcript + * reliability. Larger values indicate higher confidence. + */ + confidence: number; + /** + * Audio channel to which the utterance belongs. When using multichannel audio, + * utterances are chronologically ordered by channel. + */ + channel: number; + /** + * Transcript for the audio segment being processed. + */ + transcript: string; + /** + * Object containing each word in the transcript, along with its start time + * and end time (in seconds) from the beginning of the audio stream, and a confidence value. + */ + words: Array; + /** + * Integer indicating the speaker who is saying the word being processed. + */ + speaker?: number; + /** + * Unique identifier of the utterance + */ + id: string; +}; diff --git a/tests/mockResults.ts b/tests/mockResults.ts index bcd98989..c0f5fb7a 100644 --- a/tests/mockResults.ts +++ b/tests/mockResults.ts @@ -19,6 +19,6 @@ export const mockKey = { id: "string", key: "string", comment: "string", - created: "Date", + created: "string", scopes: ["member"], };