我过去经常调用谷歌翻译服务来下载音频文件,使用的网址是:http://translate.google.com/translate_tts?tl=en&q=Hello+world!
然而,谷歌改变了工作方式,因此我不能再下载音频文件。我已经注册了谷歌翻译应用程序接口V2的免费试用,但找不到如何获得TTS音频文件。
有什么想法吗?
发布于 2017-10-10 22:01:05
发布于 2020-05-19 15:49:39
我偶然发现了这个帖子,想给出我对@Alexandre Andrade的看法,主要是因为他没有提交任何代码。
我在一个react应用程序中做到了这一点,但同样的过程也应该适用于一个普通的web项目。
我确实将meta tag添加到我的head public/index.html中,
<head>
...
<meta name="referrer" content="no-referrer">
...
</head>
然后在我的组件中添加了音频标签:
Javascript:
const playTTS = (text, lang) => {
// Get the audio element
const audioEl = document.getElementById('tts-audio');
const url= `https://translate.google.com/translate_tts?ie=UTF-8&tl=${lang}&client=tw-ob&q=${text}`;
// add the sound to the audio element
audioEl.src = url;
//For auto playing the sound
audioEl.play();
};
html
...
<audio controls id="tts-audio"/>
...
然后,只需将函数与某些生命周期方法挂钩即可。由于我在react钩子中编写了react代码,因此我在其中一个钩子中添加了函数调用,以便在加载组件时对其进行初始化。(否则这将在componentDidMount()函数中)。
希望这对任何人都有帮助!
发布于 2018-12-29 22:31:34
https://stackoverflow.com/questions/35002003
复制相似问题