Skip to content

Commit

Permalink
Adding utterances and modifying property names
Browse files Browse the repository at this point in the history
  • Loading branch information
michaeljolley committed Jul 14, 2021
1 parent a35d86e commit e83c6d1
Show file tree
Hide file tree
Showing 14 changed files with 238 additions and 66 deletions.
47 changes: 46 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
};
```

- 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
Expand Down Expand Up @@ -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
159 changes: 109 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<number>;
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
Expand Down Expand Up @@ -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
Expand All @@ -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<string>
},
];
Expand All @@ -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<string>
}
```
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -54,4 +54,4 @@
"dependencies": {
"ws": "^7.4.6"
}
}
}
13 changes: 7 additions & 6 deletions sample/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,26 @@ 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);

/** Send a pre-recorded file for transcription */
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();
}
Expand Down
1 change: 1 addition & 0 deletions src/httpRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ export function _request<T>(
dgRes.on("end", () => {
let dgResponse;
try {
console.log(`content: ${dgResContent}`);
dgResponse = JSON.parse(dgResContent);
} catch (err) {
dgResponse = { error: dgResContent };
Expand Down
15 changes: 14 additions & 1 deletion src/projects.ts
Original file line number Diff line number Diff line change
@@ -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) {}
Expand Down Expand Up @@ -30,4 +30,17 @@ export class Projects {
`${this.apiPath}/${projectId}`
);
}

/**
* Update a specific project
* @param project project to update
*/
async update(project: Project): Promise<ProjectPatchResponse> {
return _request<ProjectPatchResponse>(
"PATCH",
this._credentials,
this._apiUrl,
`${this.apiPath}/${project.project_id}`
);
}
}
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -22,4 +23,5 @@ export * from "./usageRequestList";
export * from "./usageRequestListOptions";
export * from "./usageResponse";
export * from "./usageResponseDetail";
export * from "./utterance";
export * from "./wordBase";
4 changes: 2 additions & 2 deletions src/types/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
*/
Expand All @@ -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
*/
Expand Down
Loading

0 comments on commit e83c6d1

Please sign in to comment.