{"id":16424,"date":"2020-07-19T16:34:05","date_gmt":"2020-07-19T20:34:05","guid":{"rendered":"https:\/\/scruss.com\/blog\/?p=16424"},"modified":"2020-07-19T16:34:08","modified_gmt":"2020-07-19T20:34:08","slug":"speech-on-raspberry-pi-espeak-ng","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2020\/07\/19\/speech-on-raspberry-pi-espeak-ng\/","title":{"rendered":"speech on Raspberry Pi: espeak-ng"},"content":{"rendered":"\n<p>Audio can be a bit dismal on a Raspberry Pi. Once you get a configuration that works, sometimes you&#8217;re not sure how you got there and you&#8217;ll do anything to keep that arcane setup going. It&#8217;s better than it was.<\/p>\n\n\n\n<p>Speech synthesis or TTS adds an extra layer for potential failure. One of the popular Linux TTS systems, <a href=\"http:\/\/espeak.sourceforge.net\/\">eSpeak<\/a>, hasn&#8217;t seen much development in almost a decade and seems to only work through workarounds and hand-waving.<\/p>\n\n\n\n<p>Thankfully, there&#8217;s a fork of eSpeak that is maintained: <a href=\"https:\/\/github.com\/espeak-ng\/espeak-ng\">espeak-ng<\/a>. Better yet, it&#8217;s packaged with Raspberry Pi OS and can be installed quite easily:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo apt install espeak-ng espeak-ng-data libespeak-ng-dev\n<\/pre><\/div>\n\n\n<p>In my simple tests, it output everything I expected of it.<\/p>\n\n\n\n<p>eSpeak had a Python module that <em>kinda<\/em> worked, but espeak-ng&#8217;s is much more ambitious, and (mostly) does what it sets out to do. You can install it like this:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nsudo pip3 install py-espeak-ng\n<\/pre><\/div>\n\n\n<p><a href=\"https:\/\/pypi.org\/project\/py-espeak-ng\/\">py-espeak-ng<\/a> has some documentation, but it&#8217;s still got some trial and error in getting it to work. The biggest issue that held me up was that the  module needs to be initialized with a voice that espeak-ng already knows about. If you don&#8217;t specify a voice, or specify one that the system doesn&#8217;t know about, you won&#8217;t get any errors \u00e2\u20ac\u201d but you won&#8217;t get any output, either.<\/p>\n\n\n\n<p>Here&#8217;s a small Python example that you&#8217;ll probably want to try with no-one else within earshot. It repeats the same English phrase (a favourite of elocution teachers) in every English regional language that espeak-ng knows about. In addition, since I&#8217;m a dictionary nerd, it outputs phonetics too.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#!\/usr\/bin\/python3\n# -*- coding: utf-8 -*-\n# an espeakng elocution lesson from scruss, 2020-07\n#     I suffered this at school, now you get to as well!\n# You will need to:\n#     sudo apt install espeak-ng espeak-ng-data libespeak-ng-dev\n#     sudo pip3 install py-espeak-ng\n\nfrom espeakng import ESpeakNG\nfrom time import sleep\n\n# you have to initialize with a voice that exists\n#   `espeak-ng --voices=en` will list English ones\nesng = ESpeakNG(voice=&#039;en-gb&#039;)\nesng.pitch = 32\nesng.speed = 150\n\nphrase = &quot;Father&#039;s car is a Jaguar and pa drives rather fast. &quot;\\\n    &quot;Castles, farms and draughty barns, all go charging past.&quot;\nprint(phrase)\nprint()\n\nfor voice in esng.voices:\n    if voice&#x5B;&#039;language&#039;].startswith(&#039;en-&#039;):\n        print(&#039;Using voice:&#039;, voice&#x5B;&#039;language&#039;],\n              &#039;for&#039;, voice&#x5B;&#039;voice_name&#039;], &#039;-&#039;)\n        esng.voice = voice&#x5B;&#039;language&#039;]\n        ipa = esng.g2p(phrase, ipa=2)\n        print(voice&#x5B;&#039;language&#039;], &#039;phonetics:&#039;, ipa)\n        esng.say(phrase, sync=True)\n        print()\n        sleep(0.1)\n\n<\/pre><\/div>\n\n\n<p>Be thankful you can&#8217;t hear the output. The IPA output, however, is a thing of beauty:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n.\/espeakNG_test.py\nFather&#039;s car is a Jaguar and pa drives rather fast. Castles, farms and draughty barns, all go charging past.\n\nUsing voice: en-029 for English_(Caribbean) -\nen-029 phonetics: f\u00cb\u02c6\u00c9\u2018\u00cb\u0090daz k\u00cb\u02c6\u00c9\u2018\u00cd\u00a1\u00c9\u2122\u00c9\u00b9 \u00c9\u00aaz a d\u00cd\u00a1\u00ca\u2019\u00cb\u02c6a\u00c9\u00a1w\u00c9\u2018\u00cd\u00a1\u00c9\u2122 and p\u00cb\u02c6\u00c9\u2018\u00cb\u0090 d\u00c9\u00b9\u00cb\u02c6a\u00cd\u00a1\u00c9\u00aavz \u00c9\u00b9\u00cb\u02c6\u00c9\u2018\u00cb\u0090da f\u00cb\u02c6a\u00cd\u00a1astk\u00cb\u02c6a\u00cd\u00a1as\u00c9\u203alzf\u00cb\u02c6\u00c9\u2018\u00cd\u00a1\u00c9\u2122mz and d\u00c9\u00b9\u00cb\u02c6a\u00cd\u00a1afti b\u00cb\u02c6\u00c9\u2018\u00cd\u00a1\u00c9\u2122nz\u00cb\u02c6\u00c9\u201d\u00cb\u0090l \u00c9\u00a1\u00cb\u0152o\u00cd\u00a1\u00ca\u0160 t\u00cd\u00a1\u00ca\u0192\u00cb\u02c6\u00c9\u2018\u00cd\u00a1\u00c9\u2122d\u00cd\u00a1\u00ca\u2019\u00c9\u00aan p\u00cb\u02c6a\u00cd\u00a1ast\n\nUsing voice: en-gb for English_(Great_Britain) -\nen-gb phonetics: f\u00cb\u02c6\u00c9\u2018\u00cb\u0090\u00c3\u00b0\u00c9\u2122z k\u00cb\u02c6\u00c9\u2018\u00cb\u0090\u00c9\u00b9 \u00c9\u00aaz \u00c9\u0090 d\u00cd\u00a1\u00ca\u2019\u00cb\u02c6a\u00c9\u00a1w\u00c9\u2018\u00cb\u0090 and p\u00cb\u02c6\u00c9\u2018\u00cb\u0090 d\u00c9\u00b9\u00cb\u02c6a\u00cd\u00a1\u00c9\u00aavz \u00c9\u00b9\u00cb\u02c6\u00c9\u2018\u00cb\u0090\u00c3\u00b0\u00c9\u2122 f\u00cb\u02c6astk\u00cb\u02c6as\u00c9\u2122\u00cd\u00a1lzf\u00cb\u02c6\u00c9\u2018\u00cb\u0090mz and d\u00c9\u00b9\u00cb\u02c6afti b\u00cb\u02c6\u00c9\u2018\u00cb\u0090nz\u00cb\u02c6\u00c9\u201d\u00cb\u0090l \u00c9\u00a1\u00cb\u0152\u00c9\u2122\u00cd\u00a1\u00ca\u0160 t\u00cd\u00a1\u00ca\u0192\u00cb\u02c6\u00c9\u2018\u00cb\u0090d\u00cd\u00a1\u00ca\u2019\u00c9\u00aa\u00c5\u2039 p\u00cb\u02c6ast\n\nUsing voice: en-gb-scotland for English_(Scotland) -\nen-gb-scotland phonetics: f\u00cb\u02c6a:\u00c3\u00b0\u00c9\u0153z k\u00cb\u02c6a\u00cb\u0090r \u00c9\u00aaz \u00c9\u0090 d\u00cd\u00a1\u00ca\u2019\u00cb\u02c6a\u00c9\u00a1wa\u00cb\u0090r and p\u00cb\u02c6a: dr\u00cb\u02c6a\u00cd\u00a1\u00c9\u00aavz r\u00cb\u02c6a:\u00c3\u00b0\u00c9\u0153 f\u00cb\u02c6a:stk\u00cb\u02c6a:s\u00c9\u2122\u00cd\u00a1lzf\u00cb\u02c6a\u00cb\u0090rmz and dr\u00cb\u02c6a:fte b\u00cb\u02c6a\u00cb\u0090rnz\u00cb\u02c6\u00c9\u201d\u00cb\u0090l \u00c9\u00a1\u00cb\u0152o\u00cb\u0090 t\u00cd\u00a1\u00ca\u0192\u00cb\u02c6a\u00cb\u0090rd\u00cd\u00a1\u00ca\u2019\u00c9\u00aa\u00c5\u2039 p\u00cb\u02c6a:st\n \u00e2\u20ac\u00a6\n\n<\/pre><\/div>","protected":false},"excerpt":{"rendered":"<p>Audio can be a bit dismal on a Raspberry Pi. Once you get a configuration that works, sometimes you&#8217;re not sure how you got there and you&#8217;ll do anything to keep that arcane setup going. It&#8217;s better than it was. Speech synthesis or TTS adds an extra layer for potential failure. One of the popular [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"speech on Raspberry Pi: espeak-ng and Python","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[7,2],"tags":[],"class_list":["post-16424","post","type-post","status-publish","format-standard","hentry","category-computers-suck","category-goatee-stroking-musing-or-something"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-4gU","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/16424","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/comments?post=16424"}],"version-history":[{"count":2,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/16424\/revisions"}],"predecessor-version":[{"id":16426,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/16424\/revisions\/16426"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=16424"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=16424"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=16424"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}