speechkit-js
v0.0.1
Published
JavaScript client for interacting with the SpeechKit API
Downloads
20
Maintainers
Readme
speechkit-js
JavaScript client for interacting with the SpeechKit API.
Install
$ yarn add speechkit-js
Usage
const Speechkit = require('speechkit-js')
const speechkit = new Speechkit(<token>)
await speechkit.getVoices()
API
Kind: global class
- Speechkit
- new Speechkit(token)
- .getVoices() ⇒ Promise
- .getNewsSites() ⇒ Promise
- .createNewsSites({ title }) ⇒ Promise
- .getArticles(newsSiteId, { page }) ⇒ Promise
- .getArticle(newsSiteId, articleId) ⇒ Promise
- .createArticle(newsSiteId, [data]) ⇒ Promise
new Speechkit(token)
token
Type: string
Description: Your SpeechKit token
Required
.getVoices()
Returns a promise
Get all voices available from speechkit
const speechkit = new Speechkit(<token>)
await speechkit.getVoices()
/*
[
{
"id": 1,
"language": "en_AU",
"name": "Nicole"
},
{
"id": 2,
"language": "en_AU",
"name": "Russel"
},
...
]
*/
.getNewsSites()
Returns a promise
Get all news sites that belong to your publisher
const speechkit = new Speechkit(<token>)
await speechkit.getNewsSites()
/*
[
{
"id": 28,
"title": "Bloomberg",
"external_id": "bloomberg"
},
{
"id": 29,
"title": "The Guardian",
"external_id": "the-guardian"
},
{
"id": 30,
"title": "Der Tagesspiegel",
"external_id": "der-tagesspiegel"
},
...
]
*/
.createNewsSites({ title })
Returns a promise
title
Type: string
Description: Title of the new site
Required
Create sites to your publisher
const speechkit = new Speechkit(<token>)
await speechkit.createNewsSites({ title: 'My Site'})
/*
{
"id": 1,
"title": "My Site",
"external_id": "my-site"
}
*/
.getArticles(newsSiteId, { page })
Returns a promise
newsSiteId
Type: string
Description: The id of your site you want to fetch all articles for. This can also be your news_sites external id
Required
page
Type: integer
Description: Since this is a paginated response you can set the page to get more articles.
Get all articles for a news site
const speechkit = new Speechkit(<token>)
await speechkit.getArticles(1, { page: 1 })
/*
[
{
"id": "1",
"url": "https://www.bloomberg.com/news/articles/2016-09-09/google-s-ai-brainiacs-achieve-speech-generation-breakthrough",
"title": "Google’s DeepMind Achieves Speech-Generation Breakthrough",
"author": "Jeremy Khan",
"summary": "",
"image": "",
"published_at": "2016-09-09T13:03:00.000Z",
"body": "Google’s DeepMind Achieves Speech-Generation Breakthrough.....",
"state": "processed",
"media": [
{
"id": 25726,
"role": "body",
"content_type": "application/x-mpegURL",
"url": "https://d22tbkdovk5ea2.cloudfront.net/audio/news_sites/28/articles/12860/roles/body/voices/37/ab6faf941b7f604a77a60c5ebcacda82.m3u8",
"created_at": "2017-04-25T13:05:15.536Z",
"state": "processed"
},
{
"id": 25725,
"role": "body",
"content_type": "audio/mpeg",
"url": "https://d22tbkdovk5ea2.cloudfront.net/audio/news_sites/28/articles/12860/roles/body/voices/37/c9d36a0c25e84d98c5a40f4a6ca510ca.mp3",
"created_at": "2017-04-25T13:05:06.450Z",
"state": "processed"
}
]
}
]
*/
.getArticle(newsSiteId, articleId)
Returns a promise
newsSiteId
Type: string
Description: The id of your site you want to fetch all articles for. This can also be your news_sites external id
Required
articleId
Type: string
Description: The id of the article you want to request.
Get a specific article
const speechkit = new Speechkit(<token>)
await speechkit.getArticle(1, 1)
/*
{
"id": "1",
"url": "https://www.bloomberg.com/news/articles/2016-09-09/google-s-ai-brainiacs-achieve-speech-generation-breakthrough",
"title": "Google’s DeepMind Achieves Speech-Generation Breakthrough",
"author": "Jeremy Khan",
"summary": "",
"image": "",
"published_at": "2016-09-09T13:03:00.000Z",
"body": "Google’s DeepMind Achieves Speech-Generation Breakthrough.....",
"state": "processed",
"media": [
{
"id": 25726,
"role": "body",
"content_type": "application/x-mpegURL",
"url": "https://d22tbkdovk5ea2.cloudfront.net/audio/news_sites/28/articles/12860/roles/body/voices/37/ab6faf941b7f604a77a60c5ebcacda82.m3u8",
"created_at": "2017-04-25T13:05:15.536Z",
"state": "processed"
},
{
"id": 25725,
"role": "body",
"content_type": "audio/mpeg",
"url": "https://d22tbkdovk5ea2.cloudfront.net/audio/news_sites/28/articles/12860/roles/body/voices/37/c9d36a0c25e84d98c5a40f4a6ca510ca.mp3",
"created_at": "2017-04-25T13:05:06.450Z",
"state": "processed"
}
]
}
*/
.createArticle(newsSiteId, [data])
Returns a promise
newsSiteId
Type: string
Description: The id of your site you want to fetch all articles for. This can also be your news_sites external id
Required
data
Type: object
Description: Object containing data to create article
external_id
Type: string
Description: The id you want to identify this article as. Needs to be unique
title
Type: string
Description: The title of the article
published_at
Type: string
Description: When this article was originally published
author
Type: string
Description: The name of the author for this article
summary
Type: string
Description: The summary of the article
body
Type: string
Description: The complete body of the article
media_attributes
Type: string
Description: This is an array containing all media files you want produced. Array should contain role (string)
and/or voice_id (integer)
.
Create an article for your site. Every time you create an article we build the audio for you.
const speechkit = new Speechkit(<token>)
const body = {
external_id: 1,
title: 'The title of my article',
published_at: '2017-02-03',
author: 'John Doe',
summary: 'My summary of the article',
body: 'This is the body of the article',
media_attributes: [
{
role: 'body',
voice_id: 1
}
]
}
await speechkit.createArticle(1, body)
/*
{
"id": "1141123123",
"url": null,
"title": "The title of my article",
"author": "John Doe",
"summary": "My summary of the article",
"image": null,
"published_at": "2017-02-03T00:00:00.000Z",
"body": "This is the body of the article",
"state": "unprocessed",
"media": [
{
"id": 208,
"role": "summary",
"content_type": "",
"url": null,
"created_at": "2017-04-26T11:48:29.069Z",
"state": "unprocessed",
"voice": {
"id": 1,
"language": "en_GB",
"name": "en-GB_KateVoice"
}
},
{
"id": 209,
"role": "body",
"content_type": "",
"url": null,
"created_at": "2017-04-26T11:48:29.071Z",
"state": "unprocessed",
"voice": {
"id": 1,
"language": "en_GB",
"name": "en-GB_KateVoice"
}
}
]
}
*/
Related
- speechkit — AI-read audio for your news posts
- speechkit-state — Check if the state of SpeechKit article has been processed
License
MIT © Bu Kinoshita