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?
-
I'm also wondering if there is any official API? – Hrvoje Golcic May 10 '14 at 18:12
-
http://stackoverflow.com/questions/32053442/google-translate-tts-api-blocked – ginsengtang Aug 17 '15 at 14:54
-
This one works for me https://github.com/pndurette/gTTS – Ishtiyaq Husain Jan 27 '17 at 10:08
-
There's an official API now - see this https://stackoverflow.com/a/75452238/5050285 – rohanphadte Feb 14 '23 at 19:07
15 Answers
Old answer:
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.
Edit:
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
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
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)

- 1,971
- 2
- 16
- 24
-
3The link above is broken. The Google Translate API docs are at https://developers.google.com/translate/. – Eric Smith Aug 22 '12 at 02:53
-
2Try this http://translate.google.com/translate_tts?tl=en&q=Hello%20World Apparently there is a problem with referring the link from Stackoverflow but I tried it with HTTP request through JS and used it with HTML5 sound api, works fine! – Schahriar SaffarShargh Aug 23 '12 at 07:45
-
2It works if you try it in an incognito browser session, so yes, there shouldn't be a referer header in the request. – David d C e Freitas Nov 15 '12 at 07:54
-
-
If you want to use it with `wget` or `curl`, setting the User-agent header to an empty string seems to work fine. – vlopez Jul 10 '13 at 07:45
-
It certainly does! Although it's very limited. I would advice to purchase the service from Google or use a third-party TTS service. As for .Net projects it's rather not too difficult to implement good TTS services although they would not outweigh Google's expertise in the field. – Schahriar SaffarShargh Oct 22 '13 at 11:05
-
It works when I tried playing it using Chrome. However, it doesn't seem to work when I tried to use the url as an [html5 audio source](http://www.w3schools.com/tags/att_audio_autoplay.asp). The web service might be considering the http referrer header. – Abel Callejo Jul 04 '14 at 04:19
-
12Google has implemented abuse protection, so this URL now redirects to a CAPTCHA page. To get around this, see [my answer-as-an-update](http://stackoverflow.com/a/31791632/1986871). – Chris Cirefice Aug 03 '15 at 16:00
In an update to Schahriar SaffarShargh's answer, Google has recently implemented a 'Google abuse' feature, making it impossible to send just any regular old HTTP GET to a URL such as:
http://translate.google.com/translate_tts?tl=en&q=Hello%20World
which worked just fine and dandy previously. Now, following such a link presents you with a CAPTCHA. This also affects HTTP GET requests out-of-browser (such as with cURL), because using that URL gives a redirect to the abuse protection page (the CAPTCHA).
To start, you have to add the query parameter client
to the request URL:
http://translate.google.com/translate_tts?tl=en&q=Hello%20World&client=t
Google Translate sends &client=t
, so you should too.
Before you make that HTTP request, make sure that you set the Referer
header:
Referer: http://translate.google.com/
Evidently, the User-Agent
header is also required, but interestingly enough it can be blank:
User-Agent:
Edit: NOTE - on some user-agents, such as Android 4.X, the custom User-Agent
header is not sent, meaning that Google will not service the request. In order to solve that problem, I simply set the User-Agent
to a valid one, such as stagefright/1.2 (Linux;Android 5.0)
. Use Wireshark to debug requests (as I did) if Google's servers are not responding, and ensure that these headers are being set properly in the GET
! Google will respond with a 503 Service Unavailable
if the request fails, followed by a redirect to the CAPTCHA page.
This solution is a bit brittle; it is entirely possible that Google will change the way they handle these requests in the future, so in the end I would suggest asking Google to make a real API endpoint (free or paid) that we can use without feeling dirty for faking HTTP headers.
Edit 2: For those interested, this cURL command should work perfectly fine to download an mp3 of Hello in English:
curl 'http://translate.google.com/translate_tts?ie=UTF-8&q=Hello&tl=en&client=t' -H 'Referer: http://translate.google.com/' -H 'User-Agent: stagefright/1.2 (Linux;Android 5.0)' > google_tts.mp3
As you may notice, I have set both the Referer
and User-Agent
headers in the request, as well as added the client=t
parameter to the querystring. You may use https
instead of http
, your choice!
Edit 3: Google now requires a token for each GET request (noted by tk
in the querystring). Below is the revised cURL command that will correctly download a TTS mp3:
curl 'https://translate.google.com/translate_tts?ie=UTF-8&q=hello&tl=en&tk=995126.592330&client=t' -H 'user-agent: stagefright/1.2 (Linux;Android 5.0)' -H 'referer: https://translate.google.com/' > google_tts.mp3
Notice the &tk=995126.592330 in the querystring; this is the new token. I obtained this token by pressing the speaker icon on translate.google.com
and looking at the GET request. I simply added this querystring parameter to the previous cURL command, and it works.
NOTE: obviously this solution is very frail, and breaks at the whim of the architects at Google who introduce new things like tokens required for the requests. This token may not work tomorrow (though I will check and report back)... the point is, it is not wise to rely on this method; instead, one should turn to a commercial TTS solution, especially if using TTS in production.
For further explanation of the token generation and what you might be able to do about it, see Boude's answer.
If this solution breaks any time in the future, please leave a comment on this answer so that we can attempt to find a fix for it!

- 1
- 1

- 5,475
- 7
- 45
- 75
-
I've tried adding Referer header(with CURL), but it still redirects to Capctha page. Could you provide some script which worked for you? Thanks! – Simon Aug 12 '15 at 14:59
-
1@Syom See my edit :) also, check Wireshark or some other network analysis tool to ensure that the headers are being sent properly. As I mentioned in my answer, some devices may strip out custom headers, or do something else that is undesirable causing the request to fail. – Chris Cirefice Aug 12 '15 at 15:08
-
That works. Thank you very much! In general, Referer is not required. It jus need the User-Agent header! curl_setopt($ch, CURLOPT_USERAGENT, 'stagefright/1.2 (Linux;Android 5.0)'); – Simon Aug 13 '15 at 11:22
-
1@Syom Interesting, I wasn't able to get it to work without `Referer`... Well, one extra header 'just in case' isn't going to hurt now is it ;) – Chris Cirefice Aug 13 '15 at 13:39
-
The curl command of edit2 still works to date and trust me it's only one of the few. Thanks so much. – dr.doom Sep 07 '15 at 15:58
-
1
-
@ChrisCirefice Just curious; with the curl version, is there a way to get it to be fed a text file instead of the "Hello" string? – Anon Nov 19 '15 at 05:47
-
1@Akiva That's definitely possible as long as the language you're using can open files. You can use string concatenation to build the CURL command, or string substitution to replace the `q=XXXX` and `tl=XX` parts (which is preferred). Be aware that the *entire string must be URL-encoded*, otherwise spaces in the text query will cause timeouts. So `q=Hello world` must be encoded to `q=Hello%20world`. – Chris Cirefice Nov 19 '15 at 13:35
-
Does this still work? I'm trying to write a PHP function that downloads an mp3 of a given word with curl. I briefly had it working once, but all I'm getting now is a 2KB mp3 file that doesn't play. I'm basically getting "Our systems have detected unusual traffic from your computer network" despite using `curl_setopt( $curl, CURLOPT_USERAGENT, 'stagefright/1.2 (Linux;Android 5.0)' );` Any suggestions? – juliusbangert Dec 07 '15 at 02:48
-
@juliusbangert You're setting the *user-agent* header correctly, but is your *querystring* correct? It should look like this: `http://translate.google.com/translate_tts?ie=UTF-8&q=Hello&tl=en&client=t`. The inportant part is `client=t`; without that, the request will be blocked. You *may* also need to set the *referer* header to `http://translate.google.com/`. – Chris Cirefice Dec 07 '15 at 02:53
-
@ChrisCirefice I had `client=t` but not `ie=UTF-8` in the querystring. Either way it's not working for me. I've also tried `http` and `https`. But I'm just getting "Our systems have detected unusual traffic from your computer network". Is there any other `curl_setopt` I should be doing for this or is it possible that google have totally blocked this now? – juliusbangert Dec 07 '15 at 11:58
-
@juliusbangert Can you post a new question and reply here with a link to it? Comments aren't really a good place for debugging. I can confirm however that the TTS request works, so there must be something missing in your code. – Chris Cirefice Dec 07 '15 at 12:39
-
@ChrisCirefice Thanks, do you think there is a request limit? Like after a few requests it stops working? I was able to make it work a few times but then it goes back to the 2KB non-playable mp3. I've posted a new question here: http://stackoverflow.com/questions/34134304/using-google-text-to-speech-api-to-save-speech-audio – juliusbangert Dec 07 '15 at 13:06
-
It did work - but since somewhere last month it doesn't anmymore. It looks like the translation service now creates a token that you must send along, otherwise you get empty responses (check the URL used when using TTS, you can see the new "tk" parameter. I'm going to find a way to work around this.. – Rob Dec 30 '15 at 19:12
-
-
@RobQuist I did a bit more debugging, and yes you are correct in that Google added a `tk` parameter to the URL. After inspecting the GET request used by the speaker icon on `translate.google.com`, it generates a valid token that you can use in the cURL command. I'm not sure if these tokens expire... I'll try the cURL command tomorrow and again in a week to see if it's still valid. The problem is that this is still a fragile solution... so obviously moving to a commercial TTS service is the best option over time! I edited my answer with a cURL command that actually works (includes a token). – Chris Cirefice Dec 30 '15 at 20:51
-
@boude You suggested an edit which shows the code used to generate the new token. However, that code doesn't really belong in my answer, but would be useful as an *additional* answer. Would you mind posting an answer with your code and link back to my answer for context? I think that would be the most useful. – Chris Cirefice Jan 08 '16 at 23:06
-
It seems to work without token if you set the 'client' parameter to 'tw-ob', but this will probably change in the future. You have to also use HTTPS and set the 'User-Agent' header. – DAN Jan 12 '16 at 19:09
-
@DAN it works with 'tw-ob' and without 'tk'. But from where did you find 'tw-ob' ?! – Babak Jan 23 '16 at 13:16
-
@Babak: I've found it on StackOverflow, but I don't have the link anymore. – DAN Jan 31 '16 at 23:52
-
2This seems to be broken again. My code based on this post worked a few months back (around jan-feb '17) but is broken now (apr '17). Replacing client=t with client=tw-ob seems to do the trick though. Please verify and update the answer. – Doub Apr 29 '17 at 23:30
Expanding on Chris' answer. I managed to reverse engineer the token generation process.
The token for the request is based on the text and a global TKK variable set in the page script. These are hashed in JavaScript thus resulting in the tk param.
Somewhere in the page script you will find something like this:
TKK='403413';
This is the amount of hours passed since epoch.
The text is pumped in the following function (somewhat deobfuscated):
var query = "Hello person";
var cM = function(a) {
return function() {
return a
}
};
var of = "=";
var dM = function(a, b) {
for (var c = 0; c < b.length - 2; c += 3) {
var d = b.charAt(c + 2),
d = d >= t ? d.charCodeAt(0) - 87 : Number(d),
d = b.charAt(c + 1) == Tb ? a >>> d : a << d;
a = b.charAt(c) == Tb ? a + d & 4294967295 : a ^ d
}
return a
};
var eM = null;
var cb = 0;
var k = "";
var Vb = "+-a^+6";
var Ub = "+-3^+b+-f";
var t = "a";
var Tb = "+";
var dd = ".";
var hoursBetween = Math.floor(Date.now() / 3600000);
window.TKK = hoursBetween.toString();
fM = function(a) {
var b;
if (null === eM) {
var c = cM(String.fromCharCode(84)); // char 84 is T
b = cM(String.fromCharCode(75)); // char 75 is K
c = [c(), c()];
c[1] = b();
// So basically we're getting window.TKK
eM = Number(window[c.join(b())]) || 0
}
b = eM;
// This piece of code is used to convert d into the utf-8 encoding of a
var d = cM(String.fromCharCode(116)),
c = cM(String.fromCharCode(107)),
d = [d(), d()];
d[1] = c();
for (var c = cb + d.join(k) +
of, d = [], e = 0, f = 0; f < a.length; f++) {
var g = a.charCodeAt(f);
128 > g ? d[e++] = g : (2048 > g ? d[e++] = g >> 6 | 192 : (55296 == (g & 64512) && f + 1 < a.length && 56320 == (a.charCodeAt(f + 1) & 64512) ? (g = 65536 + ((g & 1023) << 10) + (a.charCodeAt(++f) & 1023), d[e++] = g >> 18 | 240, d[e++] = g >> 12 & 63 | 128) : d[e++] = g >> 12 | 224, d[e++] = g >> 6 & 63 | 128), d[e++] = g & 63 | 128)
}
a = b || 0;
for (e = 0; e < d.length; e++) a += d[e], a = dM(a, Vb);
a = dM(a, Ub);
0 > a && (a = (a & 2147483647) + 2147483648);
a %= 1E6;
return a.toString() + dd + (a ^ b)
};
var token = fM(query);
var url = "https://translate.google.com/translate_tts?ie=UTF-8&q=" + encodeURI(query) + "&tl=en&total=1&idx=0&textlen=12&tk=" + token + "&client=t";
document.write(url);
I managed to successfully port this to python in my fork of gTTS, so I know this works.
Edit: By now the token generation code used by gTTS has been moved into gTTS-token.
Edit 2: Google has changed the API (somewhere around 2016-05-10), this method requires some modification. I'm currently working on this. In the meantime changing the client to tw-ob seems to work.
Edit 3:
The changes are minor, yet annoying to say the least. The TKK now has two parts. Looking something like 406986.2817744745
. As you can see the first part has remained the same. The second part is the sum of two seemingly random numbers. TKK=eval('((function(){var a\x3d2680116022;var b\x3d137628723;return 406986+\x27.\x27+(a+b)})())');
Here \x3d
means =
and \x27
is '
. Both a and b change every UTC minute. At one of the final steps in the algorithm the token is XORed by the second part.
The new token generation code is:
var xr = function(a) {
return function() {
return a
}
};
var yr = function(a, b) {
for (var c = 0; c < b.length - 2; c += 3) {
var d = b.charAt(c + 2)
, d = "a" <= d ? d.charCodeAt(0) - 87 : Number(d)
, d = "+" == b.charAt(c + 1) ? a >>> d : a << d;
a = "+" == b.charAt(c) ? a + d & 4294967295 : a ^ d
}
return a
};
var zr = null;
var Ar = function(a) {
var b;
if (null !== zr)
b = zr;
else {
b = xr(String.fromCharCode(84));
var c = xr(String.fromCharCode(75));
b = [b(), b()];
b[1] = c();
b = (zr = window[b.join(c())] || "") || ""
}
var d = xr(String.fromCharCode(116))
, c = xr(String.fromCharCode(107))
, d = [d(), d()];
d[1] = c();
c = "&" + d.join("") +
"=";
d = b.split(".");
b = Number(d[0]) || 0;
for (var e = [], f = 0, g = 0; g < a.length; g++) {
var l = a.charCodeAt(g);
128 > l ? e[f++] = l : (2048 > l ? e[f++] = l >> 6 | 192 : (55296 == (l & 64512) && g + 1 < a.length && 56320 == (a.charCodeAt(g + 1) & 64512) ? (l = 65536 + ((l & 1023) << 10) + (a.charCodeAt(++g) & 1023),
e[f++] = l >> 18 | 240,
e[f++] = l >> 12 & 63 | 128) : e[f++] = l >> 12 | 224,
e[f++] = l >> 6 & 63 | 128),
e[f++] = l & 63 | 128)
}
a = b;
for (f = 0; f < e.length; f++)
a += e[f],
a = yr(a, "+-a^+6");
a = yr(a, "+-3^+b+-f");
a ^= Number(d[1]) || 0;
0 > a && (a = (a & 2147483647) + 2147483648);
a %= 1E6;
return c + (a.toString() + "." + (a ^ b))
}
;
Ar("test");
Of course I can't generate a valid url anymore, since I don't know how a and b are generated.
-
2Thanks for adding another answer, +1! I will edit my answer to point to yours for further explanation. – Chris Cirefice Jan 09 '16 at 17:16
-
-
1Google changed token structure again. Now this algorithm does not work. Any new solutions? – Simon May 15 '16 at 20:25
-
3@Syom [A simpler approach has always existed in changing the client to tw-ob.](http://stackoverflow.com/a/32053452/1017005) I'm currently looking into the changes Google has made. They appear to be minor, yet they have expanded their seed with a random text which changes every minute. I'll report back once I know more. – Boude May 18 '16 at 18:58
-
-
@Boude even without knowing how a and b are generated, ACQUIRING some TKK value is easy. TKK value changes every hour, but so far Google do not block "tk"s generated by old "tkk". even if they start requiring that you have the latest TKK, scraping it periodically from https://translate.google.com shouldn't be too hard... – Guy Rotem Apr 10 '17 at 19:15
An additional alternative is: responsivevoice.org a simple example JsFiddle is Here
HTML
<div id="container">
<input type="text" name="text">
<button id="gspeech" class="say">Say It</button>
<audio id="player1" src="" class="speech" hidden></audio>
</div>
JQuery
$(document).ready(function(){
$('#gspeech').on('click', function(){
var text = $('input[name="text"]').val();
responsiveVoice.speak("" + text +"");
<!-- http://responsivevoice.org/ -->
});
});
External Resource:
-
2This actually works without having to hack or fear that something breaks. – imrek Oct 28 '16 at 17:12
i have created this like : q= urlencode & tl = language name
Just try this :

- 696
- 8
- 12
Allright, so Google has introduces tokens (see the tk parameter in the new url) and the old solution doesn't seem to work. I've found an alternative - which I even think is better-sounding, and has more voices! The command isn't pretty, but it works. Please note that this is for testing purposes only (I use it for a little domotica project) and use the real version from acapella-group if you're planning on using this commercially.
curl $(curl --data 'MyLanguages=sonid10&MySelectedVoice=Sharon&MyTextForTTS=Hello%20World&t=1&SendToVaaS=' 'http://www.acapela-group.com/demo-tts/DemoHTML5Form_V2.php' | grep -o "http.*mp3") > tts_output.mp3
Some of the supported voices are;
- Sharon
- Ella (genuine child voice)
- EmilioEnglish (genuine child voice)
- Josh (genuine child voice)
- Karen
- Kenny (artificial child voice)
- Laura
- Micah
- Nelly (artificial child voice)
- Rod
- Ryan
- Saul
- Scott (genuine teenager voice)
- Tracy
- ValeriaEnglish (genuine child voice)
- Will
- WillBadGuy (emotive voice)
- WillFromAfar (emotive voice)
- WillHappy (emotive voice)
- WillLittleCreature (emotive voice)
- WillOldMan (emotive voice)
- WillSad (emotive voice)
- WillUpClose (emotive voice)
It also supports multiple languages and more voices - for that I refer you to their website; http://www.acapela-group.com/

- 4,927
- 4
- 26
- 41
-
-
Just as @srik reported, this solution is broken and is still as of today. It looks like *The Acapela Group* removed this php file for direct access from their server(s). – Code Doggo Apr 22 '17 at 05:54
-
1Seems to be working again, but the acapela group have since added a background music to the tts, so it is a bit more distracting to use now. The quality is great though. – Moe Tsao Feb 25 '18 at 07:51
You can download the Voice using Wget:D
wget -q -U Mozilla "http://translate.google.com/translate_tts?tl=en&q=Hello"
Save the output into a mp3 file:
wget -q -U Mozilla "http://translate.google.com/translate_tts?tl=en&q=Hello" -O hello.mp3
Enjoy !!

- 201
- 1
- 4
- 16
Google text to speech
<!DOCTYPE html>
<html>
<head>
<script>
function play(id){
var text = document.getElementById(id).value;
var url = 'http://translate.google.com/translate_tts?tl=en&q='+text;
var a = new Audio(url);
a.play();
}
</script>
</head>
<body>
<input type="text" id="text" />
<button onclick="play('text');"> Speak it </button>
</body>
</html>

- 247
- 3
- 13
Use http://www.translate.google.com/translate_tts?tl=en&q=Hello%20World
note the www.translate.google.com

- 39
- 1
-
3Doing a wget using wget http://www.translate.google.com/translate_tts?tl=en&q=Hello%20World gives this error HTTP request sent, awaiting response... 403 Forbidden 2014-08-30 14:43:26 ERROR 403: Forbidden. – simar Aug 30 '14 at 09:14
-
Guys, I am using TTS similar to this code. "http://translate.google.com/translate_tts?tl=en&q=Hello" but I get good quality reply on pc while code run on android is really bad quality. Should I allow somethime to download the file? – Amir Apr 22 '15 at 05:17
As of now, Google official Text-to-Speech service is available at https://cloud.google.com/text-to-speech/
It's free for the first 4 million characters.

- 125
- 2
- 13
I used the url as above: http://translate.google.com/translate_tts?tl=en&q=Hello%20World
And requested with python library..however I'm getting HTTP 403 FORBIDDEN
In the end I had to mock the User-Agent
header with the browser's one to succeed.

- 829
- 8
- 9
Go to console.developer.google.com
login and get an API key
or use microsoft bing's API
https://msdn.microsoft.com/en-us/library/?f=255&MSPPError=-2147217396
or even better use AT&T's speech API developer.att.com
(paid one)
For voice recognition
Public Class Voice_recognition
Public Function convertTotext(ByVal path As String, ByVal output As String) As String
Dim request As HttpWebRequest = DirectCast(HttpWebRequest.Create("https://www.google.com/speech-api/v1/recognize?xjerr=1&client=speech2text&lang=en-US&maxresults=10"), HttpWebRequest)
'path = Application.StartupPath & "curinputtmp.mp3"
request.Timeout = 60000
request.Method = "POST"
request.KeepAlive = True
request.ContentType = "audio/x-flac; rate=8000"
request.UserAgent = "speech2text"
Dim fInfo As New FileInfo(path)
Dim numBytes As Long = fInfo.Length
Dim data As Byte()
Using fStream As New FileStream(path, FileMode.Open, FileAccess.Read)
data = New Byte(CInt(fStream.Length - 1)) {}
fStream.Read(data, 0, CInt(fStream.Length))
fStream.Close()
End Using
Using wrStream As Stream = request.GetRequestStream()
wrStream.Write(data, 0, data.Length)
End Using
Try
Dim response As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
Dim resp = response.GetResponseStream()
If resp IsNot Nothing Then
Dim sr As New StreamReader(resp)
MessageBox.Show(sr.ReadToEnd())
resp.Close()
resp.Dispose()
End If
Catch ex As System.Exception
MessageBox.Show(ex.Message)
End Try
Return 0
End Function
End Class
And for text to speech: use this.
I think you'll understand this
if didn't then use vbscript to vb/C# converter.
still didn't then contact Me.
I have done this before ,can't find the code now that this why i'm not directly givin' you the code.

- 1,380
- 17
- 28

- 55
- 5
Because it came up in chat here , and the first page for googeling was this one, i decided to let all in on my findings googling some more XD
you really dont need to go any length anymore to make it work simply stand on the shoulders of giants:
there is a standard
https://dvcs.w3.org/hg/speech-api/raw-file/tip/webspeechapi.html
and an example
http://html5-examples.craic.com/google_chrome_text_to_speech.html
at least for your web projects this should work (e.g. asp.net)

- 1
- 1

- 463
- 8
- 21
#! /usr/bin/python2
# -*- coding: utf-8 -*-
def run(cmd):
import os
import sys
from subprocess import Popen, PIPE
print(cmd)
proc=Popen(cmd, stdin=None, stdout=PIPE, stderr=None, shell=True)
while True:
data = proc.stdout.readline() # Alternatively proc.stdout.read(1024)
if len(data) == 0:
print("Finished process")
break
sys.stdout.write(data)
import urllib
msg='Hello preety world'
msg=urllib.quote_plus(msg)
# -v verbosity
cmd='curl '+ \
'--output tts_responsivevoice.mp2 '+ \
"\""+'https://code.responsivevoice.org/develop/getvoice.php?t='+msg+'&tl=en-US&sv=g2&vn=&pitch=0.5&rate=0.5&vol=1'+"\""+ \
' -H '+"\""+'User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:44.0) Gecko/20100101 Firefox/44.0'+"\""+ \
' -H '+"\""+'Accept: audio/webm,audio/ogg,audio/wav,audio/*;q=0.9,application/ogg;q=0.7,video/*;q=0.6,*/*;q=0.5'+"\""+ \
' -H '+"\""+'Accept-Language: pl,en-US;q=0.7,en;q=0.3'+"\""+ \
' -H '+"\""+'Range: bytes=0-'+"\""+ \
' -H '+"\""+'Referer: http://code.responsivevoice.org/develop/examples/example2.html'+"\""+ \
' -H '+"\""+'Cookie: __cfduid=ac862i73b6a61bf50b66713fdb4d9f62c1454856476; _ga=GA1.2.2126195996.1454856480; _gat=1'+"\""+ \
' -H '+"\""+'Connection: keep-alive'+"\""+ \
''
print('***************************')
print(cmd)
print('***************************')
run(cmd)
Line:
/getvoice.php?t='+msg+'&tl=en-US&sv=g2&vn=&pitch=0.5&rate=0.5&vol=1'+"\""+ \
is responsible for language.
tl=en-US
There is another preety interesting site with tts engines that can be used in this manner.
substitute o for null iv0na.c0m
have a nice day
The 2023 Answer:
There's a Google Text to Speech Service in Google Cloud. It is an API service. To use it, you must first enable the Text-to-Speech API in Google Console.
Next, go to APIs & Services > Credentials and create a new API Key (Create Credentials > API Key).
Finally, you can call the POST API endpoint https://texttospeech.googleapis.com/v1/text:synthesize?key=[API KEY]
{ "audioConfig": { "audioEncoding": "LINEAR16", "pitch": "0.00", "speakingRate": "1.00" }, "input": { "text": "Hello World" }, "voice": { "languageCode": "en-US", "name": "en-US-Wavenet-E" } }
Response:
{
"audioContent": "UklGRr7CAABXQVZF..."
}

- 978
- 6
- 19