{"id":10645,"date":"2024-01-15T21:52:29","date_gmt":"2024-01-16T02:52:29","guid":{"rendered":"https:\/\/www.rushworth.us\/lisa\/?p=10645"},"modified":"2024-01-15T21:52:29","modified_gmt":"2024-01-16T02:52:29","slug":"python-generate-transcript-of-video-file","status":"publish","type":"post","link":"https:\/\/www.rushworth.us\/lisa\/?p=10645","title":{"rendered":"Python: Generate Transcript of Video File"},"content":{"rendered":"\n<p>There&#8217;s a speech_recognition module in Python that transcribes an <em>audio<\/em> file &#8212; since ffmpeg can convert a video file to mp3, that means you can also use Python to transcribe a video file. <\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n# requires pocketsphinx from CMU if using sphinx for speech to text recognition\nimport os\nimport speech_recognition as sr\nimport ffmpeg\n\nstrFFMPEGBinaryLocation = &#039;c:\/tmp\/ffmpeg\/bin\/ffmpeg.exe&#039;\nstrCurrentDirectory = os.getcwd()\n\nstrInputVideo = &quot;\\&quot;Z:\/Path To\/My Video\/file.MP4\\&quot;&quot;\nstrOutputFileName = &quot;converted.wav&quot;\n# Convert mp4 to wav file\nstrffmpeg_convert_mp4_to_wav = f&#039;{strFFMPEGBinaryLocation} -i {strInputVideo} {strCurrentDirectory}\/{strOutputFileName}&#039;\nos.system(strffmpeg_convert_mp4_to_wav)\n\n# Run converted wav file through speech recognizer\nr = sr.Recognizer()\naudio = sr.AudioFile(f&#039;{strCurrentDirectory}\/{strOutputFileName}&#039;)\n\nwith audio as source:\n\t#audio = r.record(source, 90)\t\t\t\t# Would need API key to process longer audio?\n\t#text = r.recognize_google(audio)\n\taudio = r.record(source)\n\ttext = r.recognize_sphinx(audio)\nprint(text)\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>There&#8217;s a speech_recognition module in Python that transcribes an audio file &#8212; since ffmpeg can convert a video file to mp3, that means you can also use Python to transcribe a video file.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1945],"tags":[1966,270,664,1965],"class_list":["post-10645","post","type-post","status-publish","format-standard","hentry","category-python","tag-code","tag-programming","tag-python","tag-speech-to-text"],"_links":{"self":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10645","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=10645"}],"version-history":[{"count":1,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10645\/revisions"}],"predecessor-version":[{"id":10646,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=\/wp\/v2\/posts\/10645\/revisions\/10646"}],"wp:attachment":[{"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=10645"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=10645"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rushworth.us\/lisa\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=10645"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}