Autosub
Automated generation of subtitles for tech talks in Thai language using Speechmatics, Gemini, GPT-4o and Claude.
Install / Use
/learn @dtinth/AutosubQuality Score
Category
Development & EngineeringSupported Platforms
README
An automated workflow for generating subtitles for Thai tech talks. It has been tested with tech talks in Thai language. The generated subtitles achieve high accuracy, with word error rate (WER) around 0.5–2.5%.
Introduction
Most automatic speech recognizers that support Thai language have troubles when it comes to technical talks. Most of them don’t know any technical term. Some can’t even spell a single English word. As a result, autogenerated captions from these systems tend to be unusable.
This workflow uses a combination of models:
- Speechmatics ASR — Transcribes Thai text with lower accuracy, but with highly-precise word-level timestamps.
- Gemini 1.5 Pro — This multimodal model can listen and watch a tech talk and generate a highly accurate transcript. Being mainly a language model, it knows a lot of technical terms. It can also handle the situation where the speaker speaks less common Thai words (such as words from northern Thai region). Being multimodal, it can read the slides in the video and generate transcripts more accurately. However, the model process media input in one second chunks, so it is not possible to obtain a precise timestamp. Moreover, it often hallucinates timecode, so the timing information from this model is unusable. It also tends to ignore formatting instructions in the prompt.
- Claude 3.5 Sonnet — Used to post-process the transcript to improve its formatting and readability. It can also fix some errors in the transcript.
Putting these models together created a subtitles file that has very little errors. I can review the subtitles by playing the talk at 2x speed and fixing the errors spotted. Previously, with a less a accurate transcript, I have to stop and fix the subtitle every few seconds. But now, with this workflow, sometimes a minute of reviewing can go by without me having to fix anything.
However, using this workflow can be quite expensive — it costs about 250 THB, or 7 USD, to process one hour of video. This cost can be cut in about half by processing just the audio, but without the video the transcription becomes slightly less accurate. (On the contrary, Speechmatics costs 0.3 USD per hour of audio.)
For examples of prompts and response from the models, see Prompt engineering section.
[!WARNING] The code in this repository is very hacky and badly written.
Prompt engineering
<table><tr><td><details><summary><strong>Prompt for generating a transcript</strong></summary>Prompt:
Generate a transcript of the speech.
- The speech is in Thai language.
- DO start a new line after each utterance or sentence.
- Each line should not be longer than 50 characters. If it is longer, split it into multiple lines, but keep the line lengths balanced.
- For English words, if it is a common word, then spell it using lowercase (e.g. oscillator). If it is a proper noun, capitalize it properly (e.g. Google Chrome). If it's an API name or part of computer code, use verbatim capitalization (e.g. getElementById).
- For Thai text, do not add a space between words. Only add spaces between sentences or when there is obvious pausing.
- For technical terms, in general, spell it in English (e.g. canvas, vertex, scene). Only transliterate it to Thai if it is a very common word and commonly spelled in Thai (e.g. ลิงก์, เคส, อัพเกรด, โปรแกรมเมอร์).
- Remove filler words like "umm" and "ah". Also fix the transcript when the speaker corrects themselves or repeats themselves due to stuttering.
The following notes should be helpful for generating the transcript more accurately:
<NOTES>
Title: Astro JS - เฟรมเวิร์กน้องใหม่ เขียนง่าย โหลดไวมาก!
Speaker: Chakkrisn Talawat, Seed Webs Founder & President at OSEDA
แนะนำ Astro สำหรับผู้เริ่มต้น หัดง่าย แม้ไม่เคยเขียน JS Framework อื่นมาก่อน
1. แนะนำ Astro
2. สร้างหน้าต่างๆ ด้วย HTML, Markdown, MDX, JSX
3. นำข้อมูลจากแหล่งต่างๆ มาแสดง เช่น WordPress, Google Sheet
4. สร้างเว็บจาก ThaiUI Starter Site
5. นำเว็บขึ้น Serverless เช่น Cloudflare Pages
</NOTES>
Remember, start a new line after each utterance or sentence, but do not break sentences into multiple lines.
Output:
ทีนี้ หัวข้อ นะครับ วันนี้เราพูดถึงเรื่อง Astro นะครับ
เขาพยายามจะ ผมรู้สึกว่า Astro เนี่ยสื่อสารดี
เขาไม่ได้บอกว่าเขาทำได้ทุกอย่าง นะครับ
เขาบอกเขาเป็น web framework ไม่ได้ ไม่ได้พยายามเน้นว่า JavaScript ด้วยนะ เพราะว่าจริงๆแล้วเนี่ย
พอมัน build เป็น static มันก็ ไม่ได้ feel ว่าต้องเป็น JavaScript ขนาดนั้น แต่ว่า เราใช้ JavaScript ในการเขียนนะ ใช่ ใช่ นะครับ
เขาบอกว่าเป็น web framework สำหรับ content driven นะครับ
ก็คือ เว็บที่เป็น content ทั้งหลาย นะครับ
อ่า มันจะเหมาะกับ Astro เขาไม่ได้ ไปสู้กับ web application ไม่ได้ไปสู้กับระบบที่มันซับซ้อน นะครับ
แต่ตัวมันน่ะซับซ้อน นะครับ แล้วก็ตัวมันก็ มีเบื้องหลังที่ขยายได้หลายแบบ นะครับ เดี๋ยวเรามาดูกัน
ผมก็ สะดุดใจคำว่า content driven นะครับ
ในฐานะที่เราก็ทำพวก CMS มาก่อน นะครับ อย่างเช่น WordPress ข้างล่างเนี่ย นะครับ
เราก็จะรู้สึกว่า เราจะต้องทำ ระบบ
ถ้า ถ้าทำเว็บที่เกี่ยวกับ content เราก็คิดถึง ก็คิดถึง WordPress ก่อนแน่นอน นะครับ
ซึ่ง มันอิงกับ server ใช่ไหม มันก็จะเป็น อันนี้ผมยังไม่เจอฝรั่งเขียนนะ แต่ผมอาจจะเขียนผิดก็ได้ นะครับ ผมแค่คิดเองว่า เออเนี่ย เวลาผมตัดสินใจว่า เรา เรามาใช้ตัวนี้เหอะเนี่ย เพราะเรารู้สึกแบบนี้ เรารู้สึกว่า WordPress เนี่ย
มันจมอยู่กับ server นะครับ ไม่ใช่ไม่ดีนะ
มันดีในแง่ว่า มันครบวงจร สำหรับเว็บขนาดเล็ก นะครับ
แต่เมื่อไหร่ก็ตาม ที่เราต้องการ scale นะครับ เราต้องการการไม่พึ่งพา server นะครับ ก็คือเรียกว่า serverless นะครับ ก็คือมี server แหละ แต่ว่า มันไป scale ได้ มันไป ทำ cache มันไป run ที่ device นะครับ
</details></td></tr></table>
<table><tr><td><details><summary><strong>Prompts for cleaning up the transcript</strong></summary>
Prompt:
Your job is to take the following transcript and improve it.
- Remove filler words, but keep politeness words such as ครับ or ค่ะ. Also fix repeated words due to speaker stuttering, or speaker correcting themselves.
- English words should not be capitalized unless it is a proper noun. English words that are not proper nouns should be converted to lowercase, except for API or code (e.g. moveTo) should be left alone.
- If a line has more than 50 characters, you can break one line of text into multiple lines, but try to keep line lengths relatively balanced.
- English words that are transliterated into Thai should be rewritten in English. For example, "โมเดลที่เราเทรนมาเนี่ยมันพิคอัพแพทเทิร์นอะไร" should be rewritten into "model ที่เรา train มาเนี่ยมัน pick up pattern อะไร". However, some words such as "โปรเจค" should be retained as "โปรเจค" because it’s very often used in Thai colloquial speech that its transliteration becomes a word on its own.
- If any mathematical equations can be formatted with unicode, please do so. For example, x^2 should be x². 2*3 can be 2×3. If the equation is too complex, you can leave it as is. Also if the equation is part of a code snippet, leave it as is.
- Do not add a space before ๆ. If there is a space before ๆ in the input, remove it from the output. However, there should be a space after ๆ.
Here is the transcript:
<TRANSCRIPT>
ทีนี้ หัวข้อ นะครับ วันนี้เราพูดถึงเรื่อง Astro นะครับ
เขาพยายามจะ ผมรู้สึกว่า Astro เนี่ยสื่อสารดี
เขาไม่ได้บอกว่าเขาทำได้ทุกอย่าง นะครับ
เขาบอกเขาเป็น web framework ไม่ได้ ไม่ได้พยายามเน้นว่า JavaScript ด้วยนะ เพราะว่าจริงๆแล้วเนี่ย
พอมัน build เป็น static มันก็ ไม่ได้ feel ว่าต้องเป็น JavaScript ขนาดนั้น แต่ว่า เราใช้ JavaScript ในการเขียนนะ ใช่ ใช่ นะครับ
เขาบอกว่าเป็น web framework สำหรับ content driven นะครับ
ก็คือ เว็บที่เป็น content ทั้งหลาย นะครับ
อ่า มันจะเหมาะกับ Astro เขาไม่ได้ ไปสู้กับ web application ไม่ได้ไปสู้กับระบบที่มันซับซ้อน นะครับ
แต่ตัวมันน่ะซับซ้อน นะครับ แล้วก็ตัวมันก็ มีเบื้องหลังที่ขยายได้หลายแบบ นะครับ เดี๋ยวเรามาดูกัน
ผมก็ สะดุดใจคำว่า content driven นะครับ
ในฐานะที่เราก็ทำพวก CMS มาก่อน นะครับ อย่างเช่น WordPress ข้างล่างเนี่ย นะครับ
เราก็จะรู้สึกว่า เราจะต้องทำ ระบบ
ถ้า ถ้าทำเว็บที่เกี่ยวกับ content เราก็คิดถึง ก็คิดถึง WordPress ก่อนแน่นอน นะครับ
ซึ่ง มันอิงกับ server ใช่ไหม มันก็จะเป็น อันนี้ผมยังไม่เจอฝรั่งเขียนนะ แต่ผมอาจจะเขียนผิดก็ได้ นะครับ ผมแค่คิดเองว่า เออเนี่ย เวลาผมตัดสินใจว่า เรา เรามาใช้ตัวนี้เหอะเนี่ย เพราะเรารู้สึกแบบนี้ เรารู้สึกว่า WordPress เนี่ย
มันจมอยู่กับ server นะครับ ไม่ใช่ไม่ดีนะ
มันดีในแง่ว่า มันครบวงจร สำหรับเว็บขนาดเล็ก นะครับ
แต่เมื่อไหร่ก็ตาม ที่เราต้องการ scale นะครับ เราต้องการการไม่พึ่งพา server นะครับ ก็คือเรียกว่า serverless นะครับ ก็คือมี server แหละ แต่ว่า มันไป scale ได้ มันไป ทำ cache มันไป run ที่ device นะครับ
</TRANSCRIPT>
The following notes should be helpful for generating the transcript more accurately:
<NOTES>
Title: Astro JS - เฟรมเวิร์กน้องใหม่ เขียนง่าย โหลดไวมาก!
Speaker: Chakkrisn Talawat, Seed Webs Founder & President at OSEDA
แนะนำ Astro สำหรับผู้เริ่มต้น หัดง่าย แม้ไม่เคยเขียน JS Framework อื่นมาก่อน
1. แนะนำ Astro
2. สร้างหน้าต่างๆ ด้วย HTML, Markdown, MDX, JSX
3. นำข้อมูลจากแหล่งต่างๆ มาแสดง เช่น WordPress, Google Sheet
4. สร้างเว็บจาก ThaiUI Starter Site
5. นำเว็บขึ้น Serverless เช่น Cloudflare Pages
</NOTES>
Provide the answer in <ANSWER> tags.
Output:
Here's the improved transcript:
<ANSWER>
ทีนี้หัวข้อวันนี้เราพูดถึงเรื่อง Astro นะครับ
ผมรู้สึกว่า Astro เนี่ยสื่อสารดี
เขาไม่ได้บอกว่าเขาทำได้ทุกอย่างนะครับ
เขาบอกเขาเป็น web framework ไม่ได้พยายามเน้นว่า JavaScript ด้วยนะ
เพราะว่าจริงๆแล้วเนี่ย พอมัน build เป็น static
มันก็ไม่ได้ feel ว่าต้องเป็น JavaScript ขนาดนั้น
แต่ว่าเราใช้ JavaScript ในการเขียนนะครับ
เขาบอกว่าเป็น web framework สำหรับ content driven นะครับ
ก็คือเว็บที่เป็น content ทั้งหลายนะครับ
มันจะเหมาะกับ Astro เขาไม่ได้ไปสู้กับ web application
ไม่ได้ไปสู้กับระบบที่มันซับซ้อนนะครับ
แต่ตัวมันน่ะซับซ้อนนะครับ แล้วก็ตัวมันก็มีเบื้องหลังที่ขยายได้หลายแบบนะครับ
เดี๋ยวเรามาดูกัน
ผมก็สะดุดใจคำว่า content driven นะครับ
ในฐานะที่เราก็ทำพวก CMS มาก่อนนะครับ อย่างเช่น WordPress ข้างล่างเนี่ยนะครับ
เราก็จะรู้สึกว่าเราจะต้องทำระบบ
ถ้าทำเว็บที่เกี่ยวกับ content เราก็คิดถึง WordPress ก่อนแน่นอนนะครับ
ซึ่ง
