Thai language Use google AppScript

code.gs below

function extractTextFromImages() {
  const sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
  const data = sheet.getDataRange().getValues();
 
  for (let i = 1; i < data.length; i++) {
    const imageUrl = data[i][0]; // Image URL in the first column
    const text = getTextFromImage(imageUrl); // Extract text using OCR
    sheet.getRange(i + 1, 2).setValue(text); // Write text to the second column
  }
}


function getTextFromImage(imageUrl) {
  const apiKey = 'K84588088688957';
  const apiUrl = `https://api.ocr.space/parse/imageurl?apikey=${apiKey}&url=${encodeURIComponent(imageUrl)}&language='tha'`; // Corrected: added backticks


  const options = {
    method: 'get',
    muteHttpExceptions: true
  };
 
  const response = UrlFetchApp.fetch(apiUrl, options);
  const json = JSON.parse(response.getContentText());
 
  // Extract the parsed text, or show "No text found" if none
  const extractedText = json.ParsedResults && json.ParsedResults[0]
                          ? json.ParsedResults[0].ParsedText
                          : "No text found";
  return extractedText;
}

i use google sheet
column 1 = image URL
column 2 = extracted text

the result
“text not found”

i follow by this channel

1 Like

This is a great OCR video tutorial, thanks for posting it. Support for Thai OCR is only available in OCR Engine2. The default ocr engine is 1. Thus you need to specify the use of ocr engine2 in your call, then it should work fine:

So in the above please change

const apiUrl = https://api.ocr.space/parse/imageurl?apikey=${apiKey}&url=${encodeURIComponent(imageUrl)}&language='tha';

to

const apiUrl = https://api.ocr.space/parse/imageurl?apikey=${apiKey}&url=${encodeURIComponent(imageUrl)}&ocrengine=2&language='tha';`

:point_right: I simply added the &ocrengine=2 parameter. All else stays the same.

I’ve problem about coding at XOCR Class library using ocrengine=2 Problem | B4X Programming Forum ,Could you help me be successful?