{"id":233535,"date":"2024-06-18T07:18:31","date_gmt":"2024-06-18T07:18:31","guid":{"rendered":"https:\/\/michigandigitalnews.com\/index.php\/2024\/06\/18\/creating-webvtt-files-for-videos-using-node-js-a-comprehensive-guide\/"},"modified":"2025-06-25T17:16:49","modified_gmt":"2025-06-25T17:16:49","slug":"creating-webvtt-files-for-videos-using-node-js-a-comprehensive-guide","status":"publish","type":"post","link":"https:\/\/michigandigitalnews.com\/index.php\/2024\/06\/18\/creating-webvtt-files-for-videos-using-node-js-a-comprehensive-guide\/","title":{"rendered":"Creating WebVTT Files for Videos Using Node.js: A Comprehensive Guide"},"content":{"rendered":"<p> [ad_1]<br \/>\n<\/p>\n<div>\n<figure class=\"figure mt-2\">&#13;<br \/>\n                        <a href=\"https:\/\/image.blockchain.news:443\/features\/FCAF30107F93017A469BDB76DCCE7D957DFC034943E2204CF5967AAF05B60663.jpg\">&#13;<br \/>\n                            <img decoding=\"async\" class=\"rounded\" src=\"https:\/\/image.blockchain.news:443\/features\/FCAF30107F93017A469BDB76DCCE7D957DFC034943E2204CF5967AAF05B60663.jpg\" alt=\"Creating WebVTT Files for Videos Using Node.js: A Comprehensive Guide\"\/>&#13;<br \/>\n&#13;<br \/>\n                        <\/a>&#13;<br \/>\n                    <\/figure>\n<p>WebVTT (.vtt) or Web Video Text Tracks Format is a widely supported format for subtitles in videos. In this guide, you&#8217;ll learn how to create WebVTT files for videos using Node.js and the AssemblyAI API, according to AssemblyAI.<\/p>\n<h2>Step 1: Set Up Your Development Environment<\/h2>\n<p>First, install <a rel=\"nofollow\" href=\"https:\/\/nodejs.org\/en\/download?ref=assemblyai.com\">Node.js<\/a> 18 or higher on your system. Create a new project folder, change directories to it, and initialize a new Node.js project:<\/p>\n<pre><code>mkdir vtt-subtitles\ncd vtt-subtitles\nnpm init -y\n<\/code><\/pre>\n<p>Open the <em>package.json<\/em> file and add <code>type: \"module\",<\/code> to the list of properties:<\/p>\n<pre><code>{\n  ...\n  \"type\": \"module\",\n  ...\n}\n<\/code><\/pre>\n<p>This will tell Node.js to use the ES Module syntax for exporting and importing modules. Then, install the <a rel=\"nofollow\" href=\"https:\/\/github.com\/AssemblyAI\/assemblyai-node-sdk?ref=assemblyai.com\">AssemblyAI JavaScript SDK<\/a>:<\/p>\n<pre><code>npm install --save assemblyai\n<\/code><\/pre>\n<p>Next, obtain an AssemblyAI API key from your <a rel=\"nofollow\" href=\"https:\/\/www.assemblyai.com\/dashboard?ref=assemblyai.com\">dashboard<\/a>. Set it as the <code>ASSEMBLYAI_API_KEY<\/code> environment variable:<\/p>\n<pre><code># Mac\/Linux:\nexport ASSEMBLYAI_API_KEY=<your_key>\n\n# Windows:\nset ASSEMBLYAI_API_KEY=<your_key>\n<\/your_key><\/your_key><\/code><\/pre>\n<h2>Step 2: Transcribe Your Video<\/h2>\n<p>With the development environment ready, start transcribing your video files. Use <a rel=\"nofollow\" href=\"https:\/\/storage.googleapis.com\/aai-web-samples\/aai-overview.mp4?ref=assemblyai.com\">this sample video<\/a> for practice. Create a file called <code>index.js<\/code> and add the following code:<\/p>\n<pre><code>import { AssemblyAI } from 'assemblyai';\n\nconst client = new AssemblyAI({ apiKey: process.env.ASSEMBLYAI_API_KEY });\n\nconst transcript = await client.transcripts.transcribe({\n  audio: \"https:\/\/storage.googleapis.com\/aai-web-samples\/aai-overview.mp4\",\n});\n<\/code><\/pre>\n<p>If the transcription is successful, the <code>transcript<\/code> object will be populated. Verify and log any errors:<\/p>\n<pre><code>if (transcript.status === \"error\") {\n  throw new Error(transcript.error);\n}\n<\/code><\/pre>\n<h2>Step 3: Generate WebVTT File<\/h2>\n<p>Generate the subtitles in WebVTT format. Import the necessary module to save the WebVTT file to disk:<\/p>\n<pre><code>import { writeFile } from \"fs\/promises\"\n<\/code><\/pre>\n<p>Add the following code to generate and download the VTT file:<\/p>\n<pre><code>const vtt = await client.transcripts.subtitles(transcript.id, \"vtt\");\nawait writeFile(\".\/subtitles.vtt\", vtt);\n<\/code><\/pre>\n<p>Customize the maximum number of characters per caption if needed:<\/p>\n<pre><code>const vtt = await client.transcripts.subtitles(transcript.id, \"vtt\", 32);\nawait writeFile(\".\/subtitles.vtt\", vtt);\n<\/code><\/pre>\n<h2>Step 4: Run the Script<\/h2>\n<p>Run the script from your shell:<\/p>\n<pre><code>node index.js\n<\/code><\/pre>\n<p>After execution, you&#8217;ll find a new file <code>subtitles.vtt<\/code> on disk:<\/p>\n<pre><code>WEBVTT\n\n00:00.200 --&gt; 00:04.430\nAssemblyAI is building AI systems to help you build AI applications with\n\n00:04.462 --&gt; 00:08.694\nspoken data. We create superhuman AI models for speech recognition,\n\n00:08.774 --&gt; 00:13.062\nsummarization, knowledge, augmentation of large language models with spoken\n<\/code><\/pre>\n<h2>Next Steps<\/h2>\n<p>Now that you have your subtitle file, you can configure it in your video player or upload it to YouTube Studio. Additionally, explore other tools to bundle or burn subtitles into your video. Check out AssemblyAI&#8217;s <a rel=\"nofollow\" href=\"https:\/\/www.assemblyai.com\/docs\/audio-intelligence?ref=assemblyai.com\">Audio Intelligence models<\/a> and <a rel=\"nofollow\" href=\"https:\/\/www.assemblyai.com\/docs\/lemur?ref=assemblyai.com\">LeMUR<\/a> for more capabilities in your audio and video applications.<\/p>\n<p>For more educational content, visit the <a rel=\"nofollow\" href=\"https:\/\/www.assemblyai.com\/blog?ref=assemblyai.com\">AssemblyAI blog<\/a> or their <a rel=\"nofollow\" href=\"https:\/\/www.youtube.com\/c\/AssemblyAI?ref=assemblyai.com\">YouTube channel<\/a>.<\/p>\n<p><span><i>Image source: Shutterstock<\/i><\/span>                    <!-- Divider --><\/p>\n<p>                    <!-- Divider --><\/p>\n<p>                    <!-- Author info START --><br \/>\n                    <!-- Author info END --><br \/>\n                    <!-- Divider -->\n                <\/div>\n<p>[ad_2]<br \/>\n<br \/><a href=\"https:\/\/blockchain.news\/news\/creating-webvtt-files-for-videos-using-nodejs-guide\">Source link <\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[ad_1] &#13; &#13; &#13; &#13; &#13; WebVTT (.vtt) or Web Video Text Tracks Format is a widely supported format for subtitles in videos. In this<\/p>\n","protected":false},"author":1,"featured_media":233536,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"_uf_show_specific_survey":0,"_uf_disable_surveys":false,"footnotes":""},"categories":[171],"tags":[],"_links":{"self":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/posts\/233535"}],"collection":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/comments?post=233535"}],"version-history":[{"count":0,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/posts\/233535\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/media\/233536"}],"wp:attachment":[{"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/media?parent=233535"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/categories?post=233535"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/michigandigitalnews.com\/index.php\/wp-json\/wp\/v2\/tags?post=233535"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}