assemblyai
Advanced tools
Comparing version 1.0.0 to 1.0.1
{ | ||
"name": "assemblyai", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
130
README.md
@@ -23,84 +23,88 @@ ## Installing the module: | ||
```javascript | ||
const assemblyai = require('assemblyai') | ||
assemblyai.setAPIKey() // Note that the value is loaded from an environment variable. | ||
``` | ||
### Initialization | ||
### Transcript | ||
The initialization of the module of course has to be at the beginning of your project. | ||
Transcribing audio from a URL | ||
```javascript | ||
const transcript = new assemblyai.Transcript() | ||
const assemblyai = require('assemblyai') | ||
assemblyai.setAPIKey("ENTER YOUR KEY HERE") | ||
``` | ||
#### Creating a job | ||
### Upload an audio file for transcription | ||
When creating a job, you are required to pass in the audio source. | ||
An example with all of the options available is below, but the only required param would be `audio_src_url`. | ||
```javascript | ||
const response = await transcript.create({ | ||
audio_src_url: "https://example.com/example.wav", | ||
model_id: 123, | ||
options: { | ||
format_text: true || false | ||
async function upload () { | ||
try { | ||
const transcript = new assemblyai.Upload('/path/to/audiofile.wav') | ||
const response = await transcript.create() | ||
const data = response.get() | ||
// do something with the JSON response | ||
console.log(data); | ||
} catch (e) { | ||
// Do some error handling here | ||
} | ||
}) | ||
} | ||
``` | ||
#### Polling until job is complete | ||
Now that we have created a job, we can start polling for it. | ||
### Transcribe audio from a URL | ||
```javascript | ||
const { id } = response.get() | ||
const complete = await transcript.poll(id) | ||
``` | ||
The only required parameter is the `audio_src_url` parameter. For more information about transcribing audio, please see the full API documentation [here](https://docs.assemblyai.com/api/#posttranscript). | ||
This ^ will wait until the job is complete or errors out until returning. | ||
If the job were to error out, an exception would be thrown. | ||
### Models | ||
Create a custom model to boost accuracy for phrases/keywords, or to add custom vocabulary. | ||
```javascript | ||
const model = new assemblyai.Model() | ||
async function transcribe () { | ||
try { | ||
const transcript = new assemblyai.Transcript() | ||
const response = await transcript.create({ | ||
audio_src_url: "https://example.com/example.wav", | ||
model_id: 123, | ||
options: { | ||
format_text: true || false | ||
} | ||
}) | ||
const { id } = response.get() | ||
const data = await transcript.poll(id) | ||
// do something with the response data. | ||
// `data` is a wrapper of the API's JSON | ||
// response. `data.get()` returns the JSON | ||
// response of the API | ||
var responseJson = data.get(); | ||
console.log(responseJson); | ||
} catch (e) { | ||
// Do some error handling here | ||
} | ||
} | ||
``` | ||
#### Creating A Model | ||
Creating a model is very simple and is almost identical to creating a job. | ||
```javascript | ||
const response = await model.create({ | ||
name: "foobar", | ||
phrases: ["foo", "bar"] | ||
}) | ||
``` | ||
#### Polling until the model has finished training | ||
### Create a custom model | ||
This API is identical to the Transcript method which is used like so: | ||
Boost accuracy for keywords/phrases, and add custom terms to the vocabulary with a custom model. For more information, please see the full API documentation [here](https://docs.assemblyai.com/guides/custom_models_101/). | ||
```javascript | ||
const { id } = response.get() | ||
await model.poll(id) | ||
async function model() { | ||
try { | ||
const instance = new assemblyai.Model() | ||
const response = await instance.create({ | ||
phrases: ['foo', 'bar'] | ||
}) | ||
const { id } = response.get() | ||
const data = await instance.poll(id) | ||
// do something with the response data. | ||
// `data` is a wrapper of the API's JSON | ||
// response. `data.get()` returns the JSON | ||
// response of the API | ||
var responseJson = data.get(); | ||
console.log(responseJson); | ||
} catch (e) { | ||
// Do some error handling | ||
} | ||
} | ||
``` | ||
### Uploading audio files for transcription | ||
```javascript | ||
const upload = new assemblyai.Upload('/path/to/some/file.wav') | ||
``` | ||
```javascript | ||
const response = await upload.create() | ||
const { text } = response.get() | ||
console.log(text) | ||
``` | ||
## The Response Object | ||
### The Response Object | ||
@@ -113,2 +117,2 @@ When using the `Response` object, you will find a couple of methods: | ||
The method that you will most likely want to use will be `get()` which returns the full JSON object from the API, one level down. | ||
The method that you will most likely want to use will be `get()` which returns the full JSON object from the API, one level down. |
@@ -21,2 +21,6 @@ const Request = require('./Http/Request') | ||
} | ||
if (json.status === 'trained') { | ||
clearInterval(interval) | ||
resolve(response) | ||
} | ||
if (json.status === 'error') { | ||
@@ -23,0 +27,0 @@ clearInterval(interval) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
11000
263
117