Animenosekai / translate

A module grouping multiple translation APIs
GNU Affero General Public License v3.0
502 stars 60 forks source link

MicrosoftTranslate.text_to_speech is not working #81

Open kuk71 opened 1 year ago

kuk71 commented 1 year ago

from translatepy.translators.microsoft import MicrosoftTranslate

t = MicrosoftTranslate()

result = t.text_to_speech("Hello", 65, "male", "eng")

Traceback (most recent call last): File "D:\Project\Python\translate\123.py", line 3, in t = MicrosoftTranslate() File "D:\Project\Python\translate\translatepy\translators\microsoft.py", line 88, in init self.session_manager = MicrosoftSessionManager(request) File "D:\Project\Python\translate\translatepy\translators\microsoft.py", line 39, in init self._parse_authorization_data() File "D:\Project\Python\translate\translatepy\translators\microsoft.py", line 46, in _parse_authorization_data token_response = self.bing_session.send(url123, data={}) File "D:\Project\Python\translate\translatepy\translators\bing.py", line 106, in send response = request.json() File "D:\Project\Python\translate\translatepy\utils\request.py", line 80, in json return loads(self.text, **kwargs) File "C:\Users\Виктор\AppData\Local\Programs\Python\Python310\lib\json__init__.py", line 346, in loads return _default_decoder.decode(s) File "C:\Users\Виктор\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 337, in decode obj, end = self.raw_decode(s, idx=_w(s, 0).end()) File "C:\Users\Виктор\AppData\Local\Programs\Python\Python310\lib\json\decoder.py", line 355, in raw_decode raise JSONDecodeError("Expecting value", s, err.value) from None json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

Process finished with exit code 1

ZhymabekRoman commented 1 year ago

Token fetch endpoint seems to shutdown and Microsoft Translate stops working. Need to drop Microsoft Translate class.

Animenosekai commented 1 year ago

Token fetch endpoint seems to shutdown and Microsoft Translate stops working. Need to drop Microsoft Translate class.

I think the author of d4n3436/GTranslate wrote a token generation function:

https://github.com/Animenosekai/translate/discussions/62#discussioncomment-5297881

ZhymabekRoman commented 1 year ago

I think the author of d4n3436/GTranslate wrote a token generation function:

The author only uses TTS API endpoint of Bing Translate web interface.

In old days I was investigating that web version of Bing Translate has a special API endpoint that generates an API token to use Microsoft Translate API. And it's intended for TTS. Microsoft Translate is like Bing Translate, but paid. So I used this backdoor to use the whole Microsoft Translate service for free by using the API token generated by the Bing TTS endpoint. Now this endpoint is unavailable.

kuk71 commented 1 year ago

Is it possible to restore access to the Bing Translate class? Now accessing this class throws an DEPRECATED exception.

d4n3436 commented 1 year ago

I think the author of d4n3436/GTranslate wrote a token generation function:

The author only uses TTS API endpoint of Bing Translate web interface.

Hello, as I mentioned before in my comment, I reverse-engineered the signature generation of the Microsoft Translator Android app, so it's now possible to use the Microsoft Translate APIs without any tokens, except for the TTS endpoint. The code is in MicrosoftTranslator.cs.

ZhymabekRoman commented 1 year ago

Hello, as I mentioned before in my comment, I reverse-engineered the signature generation of the Microsoft Translator Android app, so it's now possible to use the Microsoft Translate APIs without any tokens, except for the TTS endpoint.

Can we port your implementation to Python 3 and use it in translatepy?

d4n3436 commented 1 year ago

Can we port your implementation to Python 3 and use it in translatepy?

Sure, you can.

ZhymabekRoman commented 1 year ago

So I started to port the new Microsoft Translate implementation based on the d4n3436 version, but unfortunately I couldn't get it to work successfully. It's bad news. Good news - I implemented another endpoint by reverse engineering Microsoft SwiftKey. See #88