一个日语长文标音项目(PHP) - Assbbs
在这里备份一下,基于mecab和unidic。 可以把汉字翻译成平假名,把外来语翻译成片假名。 之前做的,后面发现对自己学日语没啥用,项目就停掉了。 plain 'pipe', 'r' , 1 = 'pipe', 'w' , 2 = 'pipe', 'w' , $pipes ; if is resource $process { fwrite $pipes …
在这里备份一下,基于mecab和unidic。 可以把汉字翻译成平假名,把外来语翻译成片假名。 之前做的,后面发现对自己学日语没啥用,项目就停掉了。 plain 'pipe', 'r' , 1 = 'pipe', 'w' , 2 = 'pipe', 'w' , $pipes ; if is resource $process { fwrite $pipes 0 , file get contents 'php://input' ; fclose $pipes 0 ; $result = stream get contents $pipes 1 ; fclose $pipes 1 ; $error = stream get contents $pipes 2 ; fclose $pipes 2 ; proc close $process ; if !empty $error { throw new Exception $error ; } http response code 200 ; echo $result; } else { throw new Exception 'Failed to open process' ; } } catch Exception $e { http response code 500 ; echo $e; } exit; } ? JPhonetic - MeCab + UniDic function hiragana str { return str.replace / \u30A1-\u30F6 /g, ch = String.fromCharCode ch.charCodeAt 0 - 0x60 ; } function notation text, dom { if !text { return; } fetch '', { method: 'POST', headers: { 'Content-Type': 'text/plain' }, body: text } .then response = response.text .then data = { let result = ''; data.split /\r?\n/ .map row = { const values = row.split '\t' ; if values.length { console.error 'Error:', error ; } ; } document.getElementById "fileInput" .addEventListener "change", async function { const file = this.files 0 ; if !file return; const formData = new FormData ; formData.append "file", file ; formData.append "url", "" ; formData.append "language", "auto" ; formData.append "isOverlayRequired", "true" ; formData.append "FileType", ".Auto" ; formData.append "IsCreateSearchablePDF", "false" ; formData.append "isSearchablePdfHideTextLayer", "true" ; formData.append "detectOrientation", "false" ; formData.append "isTable", "false" ; formData.append "scale", "true" ; formData.append "OCREngine", "3" ; formData.append "detectCheckbox", "false" ; formData.append "checkboxTemplate", "0" ; document.querySelector " text" .innerHTML = ' Loading... '; try { const res = await fetch "https://api8.ocr.space/parse/image", { method: "POST", headers: { "accept": "application/json, text/javascript, / ; q=0.01", "apikey": "donotstealthiskey ip1", "origin": "https://ocr.space", "referer": "https://ocr.space/", }, body: formData } ; const json = await res.json ; if json?.ParsedResults?. 0 ?.ParsedText { notation json?.ParsedResults?. 0 ?.ParsedText, document.querySelector " text" ; } else { document.querySelector " text" .innerHTML = ' ' + JSON.stringify json + ' '; } } catch error { document.querySelector " text" .innerHTML = ' ' + error.message + ' '; } } ;