(image: string)
| 83 | } |
| 84 | |
| 85 | recognize(image: string) { |
| 86 | if (!this.client) { |
| 87 | return; |
| 88 | } |
| 89 | image = image.substring(image.indexOf(",") + 1); |
| 90 | |
| 91 | this.client |
| 92 | .generalBasic(image, { |
| 93 | language_type: this.getLanguage(), |
| 94 | detect_language: "true", |
| 95 | }) |
| 96 | .then(function (result: { words_result: Array<{ words: string }> }) { |
| 97 | const text = result.words_result |
| 98 | .map((item) => item["words"]) |
| 99 | .join("\n"); |
| 100 | logger.toast("OCR完成,正在翻译"); |
| 101 | eventBus.at("dispatch", "translate", text); |
| 102 | }) |
| 103 | .catch(function (err: any) { |
| 104 | // 如果发生网络错误Z |
| 105 | console.log(err); |
| 106 | logger.toast("OCR失败"); |
| 107 | }); |
| 108 | } |
| 109 | } |
| 110 | export const recognizer = new Recognizer(); |
no test coverage detected