pndurette / gTTS

Python library and CLI tool to interface with Google Translate's text-to-speech API
http://gtts.readthedocs.org/
MIT License
2.31k stars 362 forks source link

Chinese example doesn't work #410

Closed beew closed 1 year ago

beew commented 1 year ago

Prerequisites

I ran one of the examples in the documentation (Chinese) https://gtts.readthedocs.io/en/latest/cli.html#examples

gtts-cli '你好' --tld cn --lang zh-cn --output 你好.mp3

The output was

Error: 'zh-cn' not in list of supported languages.
Use --all to list languages or add --nocheck to disable language check.

To check that zh-cn is supported

gtts-cli --all
  af: Afrikaans
  ar: Arabic
  bg: Bulgarian
  bn: Bengali
  bs: Bosnian
  ca: Catalan
  cs: Czech
  da: Danish
  de: German
  el: Greek
  en: English
  es: Spanish
  et: Estonian
  fi: Finnish
  fr: French
  gu: Gujarati
  hi: Hindi
  hr: Croatian
  hu: Hungarian
  id: Indonesian
  is: Icelandic
  it: Italian
  iw: Hebrew
  ja: Japanese
  jw: Javanese
  km: Khmer
  kn: Kannada
  ko: Korean
  la: Latin
  lv: Latvian
  ml: Malayalam
  mr: Marathi
  ms: Malay
  my: Myanmar (Burmese)
  ne: Nepali
  nl: Dutch
  no: Norwegian
  pl: Polish
  pt: Portuguese
  ro: Romanian
  ru: Russian
  si: Sinhala
  sk: Slovak
  sq: Albanian
  sr: Serbian
  su: Sundanese
  sv: Swedish
  sw: Swahili
  ta: Tamil
  te: Telugu
  th: Thai
  tl: Filipino
  tr: Turkish
  uk: Ukrainian
  ur: Urdu
  vi: Vietnamese
  zh-CN: Chinese (Simplified)
  zh-TW: Chinese (Mandarin/Taiwan)
  zh: Chinese (Mandarin)

But the English and French examples worked, also all pytest tests were passed.

Environment

pndurette commented 1 year ago

@beew Oh no, thank you! Let me take a look!

pndurette commented 1 year ago

@beew Ah! So I've found the issue, and it's two-fold, plus an extra thing I discovered:

  1. The documentation should be updated. That language is not available anymore.
  2. However, this should have still worked. There's a function in the code which converts the old language codes into the current ones, while raising a DeprecationWarning so nothing breaks. However, the CLI doesn't use it during the pre-validation of the language passed, so that's a bug.

And also:

  1. The .cn endpoint doesn't seem to work anymore, if you go to http://translate.google.cn it tells you to use https://translate.google.com.hk instead

I'll work on those fixes.

In the meantime, here are workarounds:

gtts-cli '你好' --tld com.hk --lang zh-CN --output 你好.mp3

Or simply, if google.com is available in your location:

gtts-cli '你好' --lang zh-CN --output 你好.mp3
pndurette commented 1 year ago

Fixed in gTTS 2.3.2!