diff --git a/README.md b/README.md index 9b675fd..7fa9592 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/routes/index.js b/routes/index.js index af4857f..2912e77 100644 --- a/routes/index.js +++ b/routes/index.js @@ -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'}); }) diff --git a/views/index.pug b/views/index.pug index 3c147e0..dbc98ef 100644 --- a/views/index.pug +++ b/views/index.pug @@ -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: @@ -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.