【发布时间】:2018-04-27 09:16:08
【问题描述】:
首先:我打算编写一个 c# 应用程序,使用户能够立即将 JRPG 和视觉小说中的文本框从日语翻译成英语或任何其他语言。后面的代码将包括检测文本框的方法,主要受汽车牌照识别的启发,但那是遥远的未来。到目前为止,我还处于起步阶段,我将 IronOCR 用于 OCR,并通过 URL 将日文字符串发送到谷歌翻译。但是由于显而易见的原因,这会导致临时禁令。我想阻止该禁令或找到一种更安全的方式在我的用例中使用谷歌翻译。到目前为止的相关代码如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using IronOcr;
using IronOcr.Languages;
namespace OCRTranslate
{
class Program
{
static void Main(string[] args)
{
Bitmap imgsource = new Bitmap(@"C:\temp\Unbenannt.png");
var Ocr = new AdvancedOcr()
{
Language = IronOcr.Languages.Japanese.OcrLanguagePack,
};
var Resulta = Ocr.Read(@"C:\temp\Unbenannt.png");
System.IO.File.WriteAllText(@"C:\temp\Unbenanntiron.txt", TranslateGoogle());
string TranslateGoogle()
{
string html = null;
string url = string.Format(@"http://translate.google.com/translate_a/t?client=j&text={0}&h1=en&sl=ja&tl=en", Resulta);
System.Net.WebClient web = new System.Net.WebClient();
web.Headers.Add(System.Net.HttpRequestHeader.UserAgent, "Mozilla/5.0");
web.Headers.Add(System.Net.HttpRequestHeader.AcceptCharset, "UTF-8");
web.Encoding = Encoding.UTF8;
html = web.DownloadString(url);
return html;
}
}
}
}
它工作得非常完美,令我惊讶的是,图片中的日文文本被翻译了,但即使一次尝试也会导致暂时禁止......欢迎任何建议甚至替代谷歌翻译。
编辑:在我的 Firefox 中使用该 URL 显然不会导致禁令。从技术上讲,我可以通过浏览器从 c# 应用程序打开 URL。浏览器使用 URL 输出一个文本文件......那么有可能通过 c# 捕获 texfile 吗?
另一个想法:我可以将 URL 发送到已经打开的 Firefox 窗口吗?
【问题讨论】:
-
如果用户没有连接到互联网怎么办?这是个不错的主意,可惜如果你没有任何访问 google 的权限,它就行不通。
-
好吧,我仍在寻找离线解决方案,但谷歌翻译解决方案是最可靠的解决方案。这台机器翻译器生成的翻译是迄今为止我遇到的最好的日语翻译尝试。
标签: c# google-translate