Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,51 @@ Examples:
GET /archive // fetch up to 1000 archive objects
GET /archive?sessionId=1_MX42...xQVJmfn4 // fetch archive(s) with session ID
GET /archive?count=10 // fetch the first 10 archive objects
GET /archive?offset=10 // fetch archives but first 10 archive objetcs
GET /archive?offset=10 // fetch archives but first 10 archive objects
GET /archive?count=10&offset=10 // fetch 10 archive objects starting from 11th
```

### Enable [Live Captions](https://developer.vonage.com/en/video/guides/live-caption)

A `POST` request to the `/captions/start` route starts transcribing audio streams and generating real-time captions for a Vonage Video session.
The session ID and token are passed in as JSON data in the body of the request

```javascript
router.post('/captions/start', async (req, res) => {
const sessionId = req.body.sessionId;
const captionsOptions = {
languageCode: 'en-US',
partialCaptions: 'true',
};
try {
const captionsResponse = await vonage.video.enableCaptions(sessionId, req.body.token, captionsOptions);
const captionsId = captionsResponse.captionsId;
res.send({ id: captionsId });
} catch (error) {
console.error("Error starting captions: ",error);
res.status(500).send(`Error starting captions: ${error}`);
}
});
```

### Disable Live Captions

A `POST` request to the `/captions/:captionsId/stop` route stops the live captioning.
The captions ID is returned by the call to the `/captions/start` endpoint.

```javascript
router.post('/captions/:captionsId/stop', async (req, res) => {
const captionsId = req.params.captionsId;
try {
await vonage.video.disableCaptions(captionsId);
res.sendStatus(202)
} catch (error) {
console.error("Error stopping captions: ",error);
res.status(500).send(`Error stopping captions: ${error}`);
}
});
```

## More information

This sample app does not provide client-side functionality
Expand Down
33 changes: 33 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,39 @@ router.all('/admin/clear-conversations', async function (req, res) {
});
});

/**
* POST /captions/start
*/
router.post('/captions/start', async (req, res) => {
const sessionId = req.body.sessionId;
const captionsOptions = {
languageCode: 'en-US',
partialCaptions: 'true',
};
try {
const captionsResponse = await vonage.video.enableCaptions(sessionId, req.body.token, captionsOptions);
const captionsId = captionsResponse.captionsId;
res.send({ id: captionsId });
} catch (error) {
console.error("Error starting captions: ",error);
res.status(500).send(`Error starting captions: ${error}`);
}
});

/**
* POST /captions/:captionsId/stop
*/
router.post('/captions/:captionsId/stop', async (req, res) => {
const captionsId = req.params.captionsId;
try {
await vonage.video.disableCaptions(captionsId);
res.sendStatus(202)
} catch (error) {
console.error("Error stopping captions: ",error);
res.status(500).send(`Error stopping captions: ${error}`);
}
});

router.get('/_/health', async function (req, res) {
res.status(200).send({status: 'OK'});
})
Expand Down
10 changes: 8 additions & 2 deletions views/index.pug
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ html(lang='en')
body
p
| This is a sample web service for use with Vonage Video Node SDK. See the Vonage
a(href='https://github.com/opentok/learning-opentok-node')
| learning-opentok-node
a(href='https://github.com/Vonage-Community/sample-video-node-learning_server')
| sample-video-node-learning_server
| repo on GitHub.
p
| Resources are defined at the following endpoints:
Expand All @@ -29,6 +29,12 @@ html(lang='en')
tr
td GET /room/:name
td Return an Application ID, session ID, and token associated with a room name.
tr
td POST /captions/start
td Starts captions.
tr
td POST /captions/:captionsId/stop
td Stops captions.
tr
td POST /archive/start
td Start an archive for the specified Vonage Video session.
Expand Down