Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detect_lang not working #60

Open
vedansh5 opened this issue Oct 21, 2022 · 7 comments
Open

detect_lang not working #60

vedansh5 opened this issue Oct 21, 2022 · 7 comments

Comments

@vedansh5
Copy link

I am using the new updated file but it's now showing error in detect_lang the error is google_trans_new.py, line 240, in detect, raise Exception Exception

@me-suzy
Copy link

me-suzy commented Oct 22, 2022

I have the same issue:

image

@regishmc
Copy link

google_new_transError: 404 (Not Found) from TTS API. Probable cause: Unknown

@napatnicky
Copy link

Did anyone can fix it? -)

@qingshuizheng
Copy link

i believe the error originates from the shutdown of translate.google.cn.
change it to translate.google.com or anything else might work.
note: not tested.

@direct-up
Copy link

我调了调detect函数里面的json解析部分,截至2023.8.17已经能检测语言了,大家把下面这一部分替换一下即可:

def detect(self, text):
    text = str(text)
    if len(text) >= 5000:
        return log.debug("Warning: Can only detect less than 5000 characters")
    if len(text) == 0:
        return ""
    headers = {
        "Referer": "http://translate.google.{}/".format(self.url_suffix),
        "User-Agent":
            "Mozilla/5.0 (Windows NT 10.0; WOW64) "
            "AppleWebKit/537.36 (KHTML, like Gecko) "
            "Chrome/47.0.2526.106 Safari/537.36",
        "Content-Type": "application/x-www-form-urlencoded;charset=utf-8"
    }
    freq = self._package_rpc(text)
    response = requests.Request(method='POST',
                                url=self.url,
                                data=freq,
                                headers=headers)
    try:
        if self.proxies == None or type(self.proxies) != dict:
            self.proxies = {}
        with requests.Session() as s:
            s.proxies = self.proxies
            r = s.send(request=response.prepare(),
                       verify=False,
                       timeout=self.timeout)

        for line in r.iter_lines(chunk_size=1024):
            decoded_line = line.decode('utf-8')
            if "MkEWBc" in decoded_line:
                # regex_str = r"\[\[\"wrb.fr\",\"MkEWBc\",\"\[\[(.*).*?,\[\[\["
                try:
                    response = json.loads(decoded_line)  # decoded_line是str格式,转化成json列表或者字典按位置提取
                    response = json.loads(response[0][2])  # 提取的内容你那个仍然是str格式,需要继续转化成json列表或者字典按位置提取
                    response_ = list(response)
                    detect_lang = response[0][2]
                except Exception:
                    raise Exception
                # data_got = data_got.split('\\\"]')[0]
                return [detect_lang, LANGUAGES[detect_lang.lower()]]
        r.raise_for_status()
    except requests.exceptions.HTTPError as e:
        # Request successful, bad response
        log.debug(str(e))
        raise google_new_transError(tts=self, response=r)
    except requests.exceptions.RequestException as e:
        # Request failed
        log.debug(str(e))
        raise google_new_transError(tts=self)

@chrk623 chrk623 mentioned this issue Mar 27, 2024
@Alex-Songs
Copy link

@direct-up 请问404问题怎么解决呢?

@chrk623
Copy link

chrk623 commented Jun 6, 2024

@direct-up 请问404问题怎么解决呢?

Try translator = google_translator(url_suffix="com")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants