0
0

PythonでGoogle翻訳APIから音声データを取得

Last updated at Posted at 2024-09-03

Google翻訳の音声データAPI???

認証情報なしで、なぜかが下記のGoogle翻訳の音声データAPIを使えます
しかも、制限なし
https://translate.google.com/translate_tts?ie=UTF-&&client=tw-ob&tl=en&q=

PythonでGoogle翻訳APIから音声データを取得

import requests
import os

def download_mp3(url, filepath):
    response = requests.get(url, stream=True)
    if response.status_code == 200:
        with open(filepath, 'wb') as file:
            for chunk in response.iter_content(1024):
                file.write(chunk)
        print("音声はダウンロードできました!")
    else:
        print("音声はダウンロードできませんでした!")

# 呼び出し
with open('toeic(1).txt') as f:
    lines = f.readlines()
    lines_strip = [line.strip() for line in lines]
# print(lines_strip)
word = "begin"
mp3_url = 'https://translate.google.com/translate_tts?ie=UTF-&&client=tw-ob&tl=en&q='
filename = "begin.mp3"
download_mp3(mp3_url+word, filename)

参考サイト

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0