bbepis / XUnity.AutoTranslator

MIT License
1.93k stars 289 forks source link

Add manual delay for every request #65

Closed SachiaLanlus closed 4 years ago

SachiaLanlus commented 4 years ago

Hello, XUnity.AutoTranslator is awesome.

In AI-Syoujyo, I need jp->cht(traditional chinese) translation. It works well for google translation. But in fact, for the jp2zh task, baidu translation is more powerful than google translation. So I decide to use baidu. But baidu api has a limit that, personal user has the QPS(query per second)=1 limit. When playing, it always generate lots of requests at the same time, and boom, it shutdown. Can you add the option in config to add manual delay?

gravydevsupreme commented 4 years ago

You can try this. Will cause a configurable delay (default 1 second) before sending a request to the endpoint. Since all requests are serial this should cause no more than 1 req./second. BaiduTranslate.zip

gravydevsupreme commented 4 years ago

Note: I have tested this, as I have no way to properly test it.

SachiaLanlus commented 4 years ago

It works, but it seems that it delay longer than 1 sec. I guess 1.5 sec, maybe.

SachiaLanlus commented 4 years ago

I just write a python script to forward the query, and set QPS limit in it, but just I prefer build-in things. So I will use your dll. reb.zip

gravydevsupreme commented 4 years ago

I was going a bit fast yesterday, so here is a better implementation (again not tested).

But this should only add a delay if necessary. The other version I sent just always added 1 second delay before sending a request.

BaiduTranslate.zip

Also, the other version I sent might block translations from appearing while having menus, etc. open. This wont.

SachiaLanlus commented 4 years ago

I was going a bit fast yesterday, so here is a better implementation (again not tested).

But this should only add a delay if necessary. The other version I sent just always added 1 second delay before sending a request.

BaiduTranslate.zip

Also, the other version I sent might block translations from appearing while having menus, etc. open. This wont.

Yes great, this works very well. Thank you