Videos
Google Text-to-Speech supports the <phoneme> tag since at least spring 2021.
However, there are a lot of potential gotchas to overcome:
- The demo page filters out
<phoneme>tags on the client side before they even reach the API. (It does the same with the<voice>tag as pointed out here) - As with Microsoft Azure Text-to-speech (see the other answer for details), each language only supports a limited set of phonemes ("letters") that can be used.
- If you use an unsupported one, the phoneme tag is completely ignored without any warning. So the official example
<phoneme alphabet="ipa" ph="หmรฆnษชหtoสbษ">manitoba</phoneme>does not work with any English variant buten-US, since all others lack the"o"or"oส"phoneme. - It's unclear if you need to use the
v1beta1API (which I can confirm is working) or if versionv1is also ok.
There is the SSML tag <phoneme> that serves your purpose.
Unfortunately, it's currently not supported in Google Cloud Text-to-speech. The available subset of SSML tags for Google Cloud is listed in the documentation. The <phoneme> tag is not in this list. An experiment using Google Cloud's text-to-speech-demo confirms that the phonemes are ignored. The content of the tag is being read as ordinary text, as has already been remarked by @Trevor in the comments.
The <phoneme> tag is, however, being supported by Microsoft Azure Text-to-Speech and Amazon Polly. In both cases, the available phonemes are limited to those available in the language being used (see here for Azure and here for Polly). The Azure documentation isn't 100% clear about the exclusion of out-of-language phonemes, but practical experiments with the Azure Text-to-Speech demo confirm that they're not working properly. In some cases, they at least seem to be replaced by the nearest available equivalent in the language used.
Being restricted to the phonemes of one language severely limits the usefulness of the phonemes tag. E.g., you can't used the feature to embed correctly pronounced content in a second language, as the second language will usually have some phonemes that are not available in the first language. Concrete language pairs in which each language has some phonemes that are not available in the other one are English/German, Spanish/German, English/Spanish.
Right click the page and select "Inspect Element", then go to the network tab. Now, refresh the page with the network panel still open. Wait until nothing is showing up there anymore. While waiting, make sure not to get your mouse near the Listen button. Once nothing is showing up in the network panel, hover and click the listen button. As soon as you hover the listen button, an entry will appear that says "batchexecute". Find this entry. It should be above entries that say log?format=json&hasfast=โฆ.
Click on that and then on the right select the "Response" tab. There should be a bunch of random characters that go off the screen very far to the right
Select just that text and copy it. The easiest way to do this is to scroll all the way to the right first and then click and hold to the right of the ending quotation mark, then move your mouse up to the line above, then move your mouse down to reach the starting quotation mark, holding the mouse the whole time.
Go to the console tab and type v= then paste then press enter. Then, paste this into the console and press enter
{
const a = document.createElement("a");
a.href = "data:audio/mp3;base64,"+JSON.parse(v)[0];
a.download = "file.mp3";
a.click();
}
The mp3 file will download.
- Google search the word of which you want to download pronunciation by entering the query :"*How to pronounce *word**"
- Right-click the page and click View page source.
- Search for Mp3. screenshot
- click the mp3 link.
- Click the 3 dots and click Download.
Today I found an interesting tool.
I know Google Translate, it is a very useful tool. But today I searched in Google for "querying pronunciation" (my mother tongue is Brazilian Portuguese, and I'm improving my English).
If you search for "<anything> pronunciation", Google will show a box where you can listen the word, and while listening you will see lip/tongue movements, you can listen also in slow motion, and the best feature I see: a "Practice" button. Clicking, it will record your voice speaking the word and it will say if you said correctly, and if not, it will give clues like "it looks you said xxx instead" or "Good Job".
I want to ask what you think about this tool. Is it suggesting things correctly? Is it an ok tool to help on listening?
Hi. I teach English, and Google has a great pronunciation help tool. You can see it at the link below for the word "therapist". Is there a better way to get to this tool / a shorter official link that I can use to direct students to this tool? Right now, I tell students to search "how to say _______" on Google, or share really long ugly links.
https://www.google.com/search?q=how+to+say+therapist&oq=how+to+say+therapist&gs_lcrp=EgZjaHJvbWUyBggAEEUYOTIHCAEQABiABDIHCAIQABiABDIHCAMQABiABDIHCAQQABiABDIHCAUQABiABDIHCAYQABiABDIHCAcQABiABDIHCAgQABiABDIHCAkQABiABNIBCDMyNzJqMGo3qAIAsAIA&sourceid=chrome&ie=UTF-8
Since this question was asked, it's gotten much harder to "scrape" MP3s from Google Translate, but Google has (finally) set up a TTS API. Interestingly it is billed in input characters, with the first 1 or 4 million input characters per month being free (depending on whether you use WaveNet or old school voices)
Nowadays to do this using gcloud on the command line (versus building this into an app) you would do roughly as follows (I'm paraphrasing the TTS quick start). You need base64, curl, gcloud, and jq for this walkthrough.
- Create a project on the GCP console, or run something like
gcloud projects create example-throwaway-tts - Enable billing for the project. Do this even if you don't intend to exceed the freebie quota.
- Use the GCP console to enable the TTS API for the project you just set up.
- Use the console again, this time to make a new service account.
- Use any old name
- Don't give it a role. You'll get a warning. This is okay.
- Select key type JSON if it isn't already selected
- Click
Create - Hold onto the JSON file that your browser downloads
- Set an environment variable to point at that file, e.g.
export GOOGLE_APPLICATION_CREDENTIALS="~/Downloads/service-account-file.json" - Get the appropriate access token:
- Tell
gcloudto use that new project:gcloud config set project example-throwaway-tts - Set a variable
TTS_ACCESS_TOKEN=gcloud auth application-default print-access-token
- Tell
- Put together a JSON request. I'll give an example below. For this example we'll call it
request.json Lastly, run the following
curl \ -H "Authorization: Bearer "$TTS_ACCESS_TOKEN \ -H "Content-Type: application/json; charset=utf-8" \ --data-raw @request.json \ "https://texttospeech.googleapis.com/v1/text:synthesize" \ | jq '.audioContent' \ | base64 --decode > very_simple_example.mp3
What this does is to
- authenticate using the default access token for the project you set up
- set the content type to JSON (so that
jqcan extract the payload) - use
request.jsonas the data to send usingcurl's--data-rawflag - extract the value of
audioContentfrom the response base64decode that content- save the whole mess as an MP3
Contents of request.json follow. You can see where to insert your desired text, adjust the voice or change output formats via audioConfig:
{
'input':{
'text':'very simple example'
},
'voice':{
'languageCode':'en-gb',
'name':'en-GB-Standard-A',
'ssmlGender':'FEMALE'
},
'audioConfig':{
'audioEncoding':'MP3'
}
}
Original Answer
As Hugolpz alludes, if you know the word or phrase you want (via a previous Translate API call), you can get MP3s from a URL like http://translate.google.com/translate_tts?ie=UTF-8&q=Bonjour&tl=fr
Note that &tl=fr ensures that you get French instead of the default English.
You will need to rate-limit yourself, but if you're looking for a small number of words or phrases you should be fine.
Similar functionality is provided by the Speech Synthesis API (under development). Third-party libraries are already there, such as ResponsiveVoice.JS.