Created
April 30, 2017 12:56
-
-
Save nikhilkumarsingh/c8267a28cf869d10db61578ad4c5c8d1 to your computer and use it in GitHub Desktop.
Googl text to speech API demo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
API_ENDPOINT = "https://translate.google.com/translate_tts" | |
headers = {'User-Agent': "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:53.0) Gecko/20100101 Firefox/53.0"} | |
text = "good morning" | |
params = { | |
'ie': 'UTF-8', | |
'q': text, | |
'tl': 'en', | |
'client': 'gtx' | |
} | |
r = requests.get(url, params = params, headers = headers) | |
print(r.status_code) | |
with open("clip.mp3", 'wb') as f: | |
f.write(r.content) | |
''' | |
Supported languages: | |
LANG_MAP = {'swahili': 'sw', 'russian': 'ru', 'ukrainian': 'uk', 'macedonian': 'mk', 'kannada': 'kn', 'hebrew': 'iw', 'chinese simplified': 'zh-CN', 'latvian': 'lv', 'icelandic': 'is', 'hungarian': 'hu', 'czech': 'cs', 'turkish': 'tr', 'esperanto': 'eo', 'irish': 'ga', 'danish': 'da', 'german': 'de', 'bulgarian': 'bg', 'basque': 'eu', 'filipino': 'tl', 'maltese': 'mt', 'thai': 'th', 'haitian creole': 'ht', 'english': 'en', 'galician': 'gl', 'chinese traditional': 'zh-TW', 'yiddish': 'yi', 'polish': 'pl', 'vietnamese': 'vi', 'belarusian': 'be', 'portuguese': 'pt', 'welsh': 'cy', 'croatian': 'hr', 'korean': 'ko', 'bengali': 'bn', 'urdu': 'ur', 'slovak': 'sk', 'azerbaijani': 'az', 'georgian': 'ka', 'afrikaans': 'af', 'norwegian': 'no', 'telugu': 'te', 'lithuanian': 'lt', 'persian': 'fa', 'estonian': 'et', 'gujarati': 'gu', 'hindi': 'hi', 'albanian': 'sq', 'tamil': 'ta', 'indonesian': 'id', 'serbian': 'sr', 'swedish': 'sv', 'french': 'fr', 'malay': 'ms', 'spanish': 'es', 'dutch': 'nl', 'italian': 'it', 'finnish': 'fi', 'arabic': 'ar', 'slovenian': 'sl', 'latin': 'la', 'japanese': 'ja', 'catalan': 'ca', 'greek': 'el', 'romanian': 'ro'} | |
''' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line 6,
should be