OCR and AI transcripts

[!NOTE]

  • Related research: https://g0v.hackmd.io/aJqHn8f5QGuBDLSMH_EinA#OCR
  • Crowd-sourced transcript: https://g0v.hackmd.io/@cofacts/rd/%2FOhGIQzoxR5eF6audQuS_FQ
  • Media manager: https://g0v.hackmd.io/@cofacts/rd/%2FC8dW2cFiR1-N5Z0wcOefuA
  • AI response introduced in: https://g0v.hackmd.io/@cofacts/rd/%2F%40cofacts%2FrknFrmdk3

Algorithm

We will use airesponses index to store the mapping between media entry ID and the AI transcripts, so that:

[!NOTE] We basically selected “After ID is extracted by media manager” in Metadata extraction

Applied tech

In the current phase, we apply the following to different types of user inputs.

The AI responses

ListArticle with mediaUrl

When mediaUrl is specified:

  1. MediaManager.query() returns queryInfo.id
  2. Look up that media hash (queryInfo id) in articles
    • articles.text may contain crowd-sourced transcripts
    • If no match, look up that id in AI responses
      • If no match, perform AI transcript and write AI response with the id
  3. Perform more_like_this on articles’ text and hyperlink fields using the AI reponse’s text.

In the process above,

CreateMediaArticle

  1. mediaManager.insert() returns MediaEntry ID
  2. Create article with MediaEntry (createNewMediaArticle)
  3. Look up that ID in AI responses
    • Since LINE bots always ListArticle before CreateMediaArticle, this step usually can find a AI response
    • If not, perform AI transcript and write the AI response
  4. Create a version of “crowd-sourced” transcript with AI transcript
    • This should be the very first version of the transcript

In the process above,

Cost estimation

To get the estimate of max possible cost, we assume an extreme case

The event count for UserInput / MessageType / <text | image | video | ...> in LINE bot in 2023/03 are:

We does the following estimation with

OCR

Previous pricing research

Google cloud vision API

  • Usage: https://cloud.google.com/vision/docs/ocr?hl=zh-tw
  • Pricing: https://cloud.google.com/vision/pricing?hl=zh-tw

Document Text Detection:

Each feature applied to an image is a billable unit. For example, if you apply Face Detection and Label Detection to the same image, you are billed for one unit of Label Detection and one unit for Face Detection.

In our case, 1 unit = 1 image. Thus:

[!TIP] 3.3 USD / mo

Tesseract

Free of charge, but can be limited in our previous experience

STT

Whisper API

  • NodeJS API
  • https://openai.com/pricing
    • $0.006 / minute (rounded to the nearest second)

[!TIP] 114 USD / mo

自架 Whisper

GPU machine cost 遠大於 Whisper API https://cloud.google.com/compute/gpus-pricing#tpus

Google speech to text

Usage: https://cloud.google.com/speech-to-text/docs?hl=zh-tw Pricing: https://cloud.google.com/speech-to-text/pricing By opting in to data logging, you can allow Google to record audio data sent to Speech-to-Text. This data helps Google improve the machine learning models used for speech transcription. Customers who opt in to data logging benefit from lower Speech-to-Text pricing.

V1 API

[!TIP] 300 USD / mo

V2 API

Sync request
Async request (dynamic batch)
Effectiveness

昨天我試了一下 google speech to text v2 (Chirp) 影片與 whisper 幻出來的結果:https://cofacts.tw/article/sfTx-IoBAjOeMOklkePx

而 Google Chirp 模型的結果如圖 感覺比 Whisper 的 medium model 還差,錯字多到 Elasticsearch 的 bigram 也無法有效 index

Multimodal LLM

Gemini Flash 1.5 (Gemini API)

Pricing: https://ai.google.dev/pricing

[!TIP] 103 USD / mo

Gemini Flash 1.5 (Vertex AI)

Pricing

[!TIP] 150 USD / mo

Tech detail

Whisper

VAD to reduce hallucination

https://npm.io/search/keyword:vad

WebRTC VAD
faster-whisper + Silenro VAD
Cobra Vad

https://picovoice.ai/blog/voice-activity-detection-in-nodejs/

WhisperX on replicate

目標:https://replicate.com/victor-upmeet/whisperx/readme

WhisperX by Ronny Wang

Google cloud speech-to-text

Google vision API

Determine confidence level threshold with the following items.

Script: https://colab.research.google.com/drive/1yyMyShq1j3LRX1zdQE-3sLH5fNmTvdmp#scrollTo=lvZwFTLVOo4C&line=32&uniqifier=1

Evaluation: https://docs.google.com/spreadsheets/d/1d7OAVygXwwb3JgjpSKaRrm1bkzUOAapTtebi-I3Na7A/edit#gid=0

Google video intelligence

2-in-1: transcript + text detection https://cloud.google.com/video-intelligence/docs/text-detection

Gemini

Gemini 1.5 Flash on Google AI

Gemini 1.5 Flash on Vertex AI


Gemini Experiments

Test subjects used in unit tests

Model selection


Model Test subject Time Token usage
gemini-2.0-flash-exp Direct sales 24s 1,282 → 96 (∑ 1,378)
gemini-2.0-flash-exp Ginger 41s 15,837 → 221 (∑ 16,058)
gemini-2.0-flash-exp Tiktok 37s 9,347 → 108 (∑ 9,455)
gemini-1.5-pro-002 Direct sales 43s 1,282 → 101 (∑ 1,383)
gemini-1.5-pro-002 Ginger 1m 17s 15,837 → 205 (∑ 16,042)
gemini-1.5-pro-002 Tiktok 1m 12s 9,347 → 94 (∑ 9,441)
gemini-1.5-flash-002 Direct sales 46.23s 1,282 → 97 (∑ 1,379)
gemini-1.5-flash-002 Ginger 1m 27s 15,837 → 2,048 (∑ 17,885) Hallucinated
gemini-1.5-flash-002 Tiktok 1m 6s 9,347 → 96 (∑ 9,443)

2025/2/10 update: Gemini 2.0 is generally available; however it’s speed is too slow. Comparisons: https://github.com/cofacts/rumors-api/pull/361#issue-2839000967

RoadMap

Migration of exisitng media articles

  1. Release AI transcript –> lock down number of articles to migrate
  2. Get articles that needs migration by filtering open data
  3. Collect articles that needs migration in Google sheet
  4. Article ID –> Transcript on Colab
    • article ID –> media type & media article
      • Image –> call Google API –> transcript
      • Video, audio –> call Whisper in colab (free XD) –> transcript
    • Store transcript in spreadsheet
  5. Write sheet content to DB
    1. Export google sheet contnet
    2. Load them using one-off Node.JS script that calls writeAITranscript(articleId, text)
      • The script will write articles.text (for search) and ydoc (For collab)
      • We probably don’t need airesponses

Time