谷歌文字转语音 API [英] Google Text-To-Speech API

查看:115
本文介绍了谷歌文字转语音 API的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何在我的 .NET 项目中使用 Google Text-to-Speech API.我想我需要调用一个 URL 来使用 web 服务,但我的想法还不清楚.有人可以帮忙吗?

I want to know how can I use Google Text-to-Speech API in my .NET project. I think I need to call a URL to use the web service, but the idea for me is not clear. Can anyone help?

推荐答案

旧答案:

尝试使用此 URL:http://translate.google.com/translate_tts?tl=en&q=Hello%20World它会自动生成一个 wav 文件,您可以通过任何 .net 编程通过 HTTP 请求轻松获取该文件.

Try using this URL: http://translate.google.com/translate_tts?tl=en&q=Hello%20World It will automatically generate a wav file which you can easily get with an HTTP request through any .net programming.

哦,谷歌,您认为您可以通过脆弱的 http 标头验证阻止人们使用您出色的服务.

Ohh Google, you thought you could prevent people from using your wonderful service with flimsy http header verification.

以下是获得多种语言回复的解决方案(我将尝试添加更多语言):

Here is a solution to get a response in multiple languages (I'll try to add more as we go):

NodeJS

// npm install `request`
const fs = require('fs');
const request = require('request');
const text = 'Hello World';

const options = {
    url: `https://translate.google.com/translate_tts?ie=UTF-8&q=${encodeURIComponent(text)}&tl=en&client=tw-ob`,
    headers: {
        'Referer': 'http://translate.google.com/',
        'User-Agent': 'stagefright/1.2 (Linux;Android 5.0)'
    }
}

request(options)
    .pipe(fs.createWriteStream('tts.mp3'))

<小时>

卷曲

curl 'https://translate.google.com/translate_tts?ie=UTF-8&q=Hello%20Everyone&tl=en&client=tw-ob' -H 'Referer: http://translate.google.com/' -H 'User-Agent: stagefright/1.2 (Linux;Android 5.0)' > google_tts.mp3

请注意,标题基于@Chris Cirefice 的示例,如果它们在某个时候停止工作,我将尝试重新创建此代码运行的条件.当前标题的所有功劳都归功于他和 WireShark 的出色工具.(也感谢谷歌没有修补这个)

Note that the headers are based on @Chris Cirefice's example, if they stop working at some point I'll attempt to recreate conditions for this code to function. All credits for the current headers go to him and the wonderful tool that is WireShark. (also thanks to Google for not patching this)

这篇关于谷歌文字转语音 API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆