From 8a4dec80bf9540e2d12e04f38dc8381bebc271c5 Mon Sep 17 00:00:00 2001 From: Dwane Hemmings Date: Fri, 13 Sep 2024 15:39:02 -0400 Subject: [PATCH 1/4] Update index.pug --- views/index.pug | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) 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. From a747c645f249c4d795e320323cb7f8f639a3b636 Mon Sep 17 00:00:00 2001 From: Dwane Hemmings Date: Fri, 13 Sep 2024 15:45:48 -0400 Subject: [PATCH 2/4] Update index.js adds captions endpoints --- routes/index.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/routes/index.js b/routes/index.js index af4857f..424c871 100644 --- a/routes/index.js +++ b/routes/index.js @@ -432,6 +432,43 @@ 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 (err) { + console.warn(err); + res.status(500); + res.send(`Error starting captions: ${err}`); + return; + } +}); + +/** + * 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 (err) { + console.warn(err); + res.status(500); + res.send(`Error stopping captions: ${err}`); + return; + } +}); + router.get('/_/health', async function (req, res) { res.status(200).send({status: 'OK'}); }) From 9fe93262cab3524ba232d7f52c265fcb900be371 Mon Sep 17 00:00:00 2001 From: Dwane Hemmings Date: Fri, 13 Sep 2024 15:54:49 -0400 Subject: [PATCH 3/4] Update index.js some clean up --- routes/index.js | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/routes/index.js b/routes/index.js index 424c871..2912e77 100644 --- a/routes/index.js +++ b/routes/index.js @@ -445,11 +445,9 @@ router.post('/captions/start', async (req, res) => { const captionsResponse = await vonage.video.enableCaptions(sessionId, req.body.token, captionsOptions); const captionsId = captionsResponse.captionsId; res.send({ id: captionsId }); - } catch (err) { - console.warn(err); - res.status(500); - res.send(`Error starting captions: ${err}`); - return; + } catch (error) { + console.error("Error starting captions: ",error); + res.status(500).send(`Error starting captions: ${error}`); } }); @@ -461,11 +459,9 @@ router.post('/captions/:captionsId/stop', async (req, res) => { try { await vonage.video.disableCaptions(captionsId); res.sendStatus(202) - } catch (err) { - console.warn(err); - res.status(500); - res.send(`Error stopping captions: ${err}`); - return; + } catch (error) { + console.error("Error stopping captions: ",error); + res.status(500).send(`Error stopping captions: ${error}`); } }); From 14a5b62728be7031ebed742fe52dbc19a1c945af Mon Sep 17 00:00:00 2001 From: Dwane Hemmings Date: Fri, 13 Sep 2024 16:05:54 -0400 Subject: [PATCH 4/4] Update README.md --- README.md | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) 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