<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/addendum-text-to-speech-with-the-googlelanguager-package/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://shirinsplayground.netlify.com/2018/06/googlelanguager/"> Shirin's playgRound</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>After posting my short blog post about <a rel="nofollow" href="https://shirinsplayground.netlify.com/2018/06/text_to_speech_r/" target="_blank">Text-to-speech with R</a>, I got two very useful tips. One was to use the <code>googleLanguageR</code> package, which uses the Google Cloud Text-to-Speech API.</p>
<p>And indeed, it was very easy to use and the resulting audio sounded much better than what I tried before!</p>
<p>Here’s a short example of how to use the package for TTS:</p>
<div>
<h2>Set up Google Cloud and authentification</h2>
<p>You first need to set up a Google Cloud Account and provide credit card information (the first year is free to use, though). If you haven’t used Google Cloud before, you will need to wait until you activated your account; in my case, I had to wait two days until they sent a small amount of money to my bank account which I then needed to enter in order to verify the information.</p>
<p>Then, you create a project, activate the API(s) you want to use and create the authentication information as a JSON file. More information on how to do this is described <a rel="nofollow" href="http://code.markedmondson.me/googleLanguageR/index.html" target="_blank">here</a>.</p>
<p>Install and load the library and give the path to the saved authentication JSON file.</p>
<pre><code>library(googleLanguageR)
gl_auth(&quot;path_to_authentication.json&quot;)</code></pre>
<div>
<h3>Text-to-Speech with googleLanguageR</h3>
<p>Now, we can use the <a rel="nofollow" href="http://code.markedmondson.me/googleLanguageR/articles/text-to-speech.html" target="_blank">Google Cloud Text-to-Speech API</a> from R.</p>
<blockquote>
<p>“Google Cloud Text-to-Speech enables developers to synthesize natural-sounding speech with 30 voices, available in multiple languages and variants. It applies DeepMind’s groundbreaking research in WaveNet and Google’s powerful neural networks to deliver the highest fidelity possible. With this easy-to-use API, you can create lifelike interactions with your users, across many applications and devices.” <a rel="nofollow" href="http://code.markedmondson.me/googleLanguageR/articles/text-to-speech.html" target="_blank">http://code.markedmondson.me/googleLanguageR/articles/text-to-speech.html</a></p>
</blockquote>
<pre><code>content &lt;- &quot;A common mistake that people make when trying to design something completely foolproof is to underestimate the ingenuity of complete fools.&quot;</code></pre>
<p>We can ask for a list of languages with the <code>gl_talk_languages()</code> function; here, I am looking at all English language options:</p>
<pre><code>gl_talk_languages(languageCode = &quot;en&quot;)</code></pre>
<pre><code>## # A tibble: 18 x 4
##    languageCodes name             ssmlGender naturalSampleRateHertz
##    </code></pre></div></div>