snipt

Ctrl+h for KB shortcuts

Bash

eng2audo

eng2audio () {
# see this: https://gist.github.com/michalfapso/3110049/raw
# http://michalfapso.blogspot.com.br/2012/01/using-google-text-to-speech.html
# http://mostovenko.blogspot.com.br/2012/04/voicing-messages-in-python-or-fun-with.html
# author: Sergio Luiz Araujo Silva
# site: vivaotux.blogspot.com

if   ping -q -c2 www.google.com >/dev/null ; then
     FILENAME="${@:?Usage: $0 give me some words to speech}"
     FILENAME=`awk '{print tolower($0)}' <<< "$FILENAME"`
     url="http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q="
     wget -q -U Mozilla -O "${FILENAME// /_}.mp3" "${url}${FILENAME// /+}+' '"
     [ -f "${FILENAME// /_}.mp3" -a ! -s "${FILENAME// /_}.mp3" ] && { rm -f "${FILENAME// /_}.mp3" ; echo 'error!'; }
     command -v mpg321 > /dev/null && mpg321 -q "${FILENAME// /_}.mp3"
     echo "[sound:${FILENAME// /_}.mp3]" | xclip -selection c
fi
}

Description

This script get mp3 sound from a string
https://snipt.net/embed/190e0f02af8bf0f346db38297f719cb9/
/raw/190e0f02af8bf0f346db38297f719cb9/
190e0f02af8bf0f346db38297f719cb9
bash
Bash
18
2019-05-27T06:11:16
True
False
False
Jun 16, 2013 at 01:02 PM
/api/public/snipt/64449/
eng2audo
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1"> 1</a> <a href="#L-2"> 2</a> <a href="#L-3"> 3</a> <a href="#L-4"> 4</a> <a href="#L-5"> 5</a> <a href="#L-6"> 6</a> <a href="#L-7"> 7</a> <a href="#L-8"> 8</a> <a href="#L-9"> 9</a> <a href="#L-10">10</a> <a href="#L-11">11</a> <a href="#L-12">12</a> <a href="#L-13">13</a> <a href="#L-14">14</a> <a href="#L-15">15</a> <a href="#L-16">16</a> <a href="#L-17">17</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>eng2audio <span class="o">()</span> <span class="o">{</span> </span><span id="L-2"><a name="L-2"></a><span class="c1"># see this: https://gist.github.com/michalfapso/3110049/raw</span> </span><span id="L-3"><a name="L-3"></a><span class="c1"># http://michalfapso.blogspot.com.br/2012/01/using-google-text-to-speech.html</span> </span><span id="L-4"><a name="L-4"></a><span class="c1"># http://mostovenko.blogspot.com.br/2012/04/voicing-messages-in-python-or-fun-with.html</span> </span><span id="L-5"><a name="L-5"></a><span class="c1"># author: Sergio Luiz Araujo Silva</span> </span><span id="L-6"><a name="L-6"></a><span class="c1"># site: vivaotux.blogspot.com</span> </span><span id="L-7"><a name="L-7"></a> </span><span id="L-8"><a name="L-8"></a><span class="k">if</span> ping -q -c2 www.google.com &gt;/dev/null <span class="p">;</span> <span class="k">then</span> </span><span id="L-9"><a name="L-9"></a> <span class="nv">FILENAME</span><span class="o">=</span><span class="s2">&quot;</span><span class="si">${</span><span class="p">@:?Usage: </span><span class="nv">$0</span><span class="p"> give me some words to speech</span><span class="si">}</span><span class="s2">&quot;</span> </span><span id="L-10"><a name="L-10"></a> <span class="nv">FILENAME</span><span class="o">=</span><span class="sb">`</span>awk <span class="s1">&#39;{print tolower($0)}&#39;</span> <span class="o">&lt;&lt;&lt;</span> <span class="s2">&quot;</span><span class="nv">$FILENAME</span><span class="s2">&quot;</span><span class="sb">`</span> </span><span id="L-11"><a name="L-11"></a> <span class="nv">url</span><span class="o">=</span><span class="s2">&quot;http://translate.google.com/translate_tts?ie=UTF-8&amp;tl=en&amp;q=&quot;</span> </span><span id="L-12"><a name="L-12"></a> wget -q -U Mozilla -O <span class="s2">&quot;</span><span class="si">${</span><span class="nv">FILENAME</span><span class="p">// /_</span><span class="si">}</span><span class="s2">.mp3&quot;</span> <span class="s2">&quot;</span><span class="si">${</span><span class="nv">url</span><span class="si">}${</span><span class="nv">FILENAME</span><span class="p">// /+</span><span class="si">}</span><span class="s2">+&#39; &#39;&quot;</span> </span><span id="L-13"><a name="L-13"></a> <span class="o">[</span> -f <span class="s2">&quot;</span><span class="si">${</span><span class="nv">FILENAME</span><span class="p">// /_</span><span class="si">}</span><span class="s2">.mp3&quot;</span> -a ! -s <span class="s2">&quot;</span><span class="si">${</span><span class="nv">FILENAME</span><span class="p">// /_</span><span class="si">}</span><span class="s2">.mp3&quot;</span> <span class="o">]</span> <span class="o">&amp;&amp;</span> <span class="o">{</span> rm -f <span class="s2">&quot;</span><span class="si">${</span><span class="nv">FILENAME</span><span class="p">// /_</span><span class="si">}</span><span class="s2">.mp3&quot;</span> <span class="p">;</span> <span class="nb">echo</span> <span class="s1">&#39;error!&#39;</span><span class="p">;</span> <span class="o">}</span> </span><span id="L-14"><a name="L-14"></a> <span class="nb">command</span> -v mpg321 &gt; /dev/null <span class="o">&amp;&amp;</span> mpg321 -q <span class="s2">&quot;</span><span class="si">${</span><span class="nv">FILENAME</span><span class="p">// /_</span><span class="si">}</span><span class="s2">.mp3&quot;</span> </span><span id="L-15"><a name="L-15"></a> <span class="nb">echo</span> <span class="s2">&quot;[sound:</span><span class="si">${</span><span class="nv">FILENAME</span><span class="p">// /_</span><span class="si">}</span><span class="s2">.mp3]&quot;</span> <span class="p">|</span> xclip -selection c </span><span id="L-16"><a name="L-16"></a><span class="k">fi</span> </span><span id="L-17"><a name="L-17"></a><span class="o">}</span> </span></pre></div> </td></tr></table>