{"id":17227,"date":"2023-06-21T23:11:32","date_gmt":"2023-06-22T03:11:32","guid":{"rendered":"https:\/\/scruss.com\/blog\/?p=17227"},"modified":"2023-06-22T09:26:37","modified_gmt":"2023-06-22T13:26:37","slug":"speech-from-python-with-the-syn6988-module","status":"publish","type":"post","link":"https:\/\/scruss.com\/blog\/2023\/06\/21\/speech-from-python-with-the-syn6988-module\/","title":{"rendered":"Speech from Python with the SYN6988 module"},"content":{"rendered":"\n<p>I&#8217;ve had one of these cheap(ish &#8211; $15) sound modules from AliExpress for a while. I hadn&#8217;t managed to get much out of it before, but I poked about at it a little more and found I was trying to drive the wrong chip. Aha! Makes all the difference.<\/p>\n\n\n\n<p>So here&#8217;s a short narration from <a href=\"https:\/\/allpoetry.com\/All-Watched-Over-By-Machines-Of-Loving-Grace\">my favourite Richard Brautigan poem,<\/a> read by the SYN6988. <\/p>\n\n\n\n<p><strong>Sensitive listener alert!<\/strong> There is a static click midway through. I edited out the clipped part, but it&#8217;s still a little jarring. It would always do this at the same point in playback, for some reason.<\/p>\n\n\n\n<figure class=\"wp-block-audio\"><audio controls src=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2023\/06\/molg-syn6988.mp3\"><\/audio><\/figure>\n\n\n\n<p>The only Pythonish code I could find for these chips was meant for the older SYN6288 and MicroPython (<a href=\"https:\/\/github.com\/TPYBoard\/TPYBoard_lib\/blob\/master\/14.SYN6288%20---%20SYN6288%E8%AF%AD%E9%9F%B3%E5%90%88%E6%88%90%E6%A8%A1%E5%9D%97\/syn6288.py\">syn6288.py<\/a>). I have no idea what I&#8217;m doing, but with some trivial modification, it makes sound.<\/p>\n\n\n\n<p>I used the simple serial UART connection: RX -&gt; TX, TX -&gt; RX, 3V3 to 3V3 and GND to GND. My board is hard-coded to run at 9600 baud. I used the USB serial adapter that came with the board.<\/p>\n\n\n\n<p>Here&#8217;s the code that read that text:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: python; title: ; notranslate\" title=\"\">\n#!\/usr\/bin\/env python3\n# -*- coding: utf-8 -*-\n\nimport serial\nimport time\n\n# NB via MicroPython and old too! Also for a SYN6288, which I don&#039;t have\n# nabbed from https:\/\/github.com\/TPYBoard\/TPYBoard_lib\/\n\ndef sendspeak(port, data):\n    eec = 0\n    buf = &#x5B;0xFD, 0x00, 0, 0x01, 0x01]\n    buf&#x5B;2] = len(data) + 3\n    buf += list(bytearray(data, encoding=&#039;utf-8&#039;))\n    for i in range(len(buf)):\n        eec ^= int(buf&#x5B;i])\n    buf.append(eec)\n    port.write(bytearray(buf))\n\nser = serial.Serial(&quot;\/dev\/ttyUSB1&quot;, 9600)\nsendspeak(ser, &quot;&#x5B;t5]I like to think &#x5B;p100](it &#x5B;t7]has&#x5B;t5] to be!)&#x5B;p100] of a cybernetic ecology &#x5B;p100]where we are free of our labors and joined back to nature, &#x5B;p100]returned to our mammal brothers and sisters, &#x5B;p100]and all watched over by machines of loving grace&quot;)\ntime.sleep(8)\nser.close()\n<\/pre><\/div>\n\n\n<p>This code is bad. All I did was prod stuff until it stopped <em>not<\/em> working. Since all I have to work from includes a datasheet in Chinese (from here: <a href=\"http:\/\/www.voicetx.com\/product\/detail.html?id=11\">??????-SYN6988???TTS????<\/a>) there&#8217;s lots of stuff  I could do better. I used the tone and pause tags to give the reading a little more life, but it&#8217;s still a bit flat. For $15, though, a board that makes a fair stab at reading English is not bad at all. We can&#8217;t all afford vintage DECtalk hardware.<\/p>\n\n\n\n<p>The one thing I didn&#8217;t do is used the SYN6988&#8217;s <em>Busy\/Ready<\/em> line to see if it was still busy reading. That means I could send it text as soon as it was ready, rather than pausing for 8 seconds after the speech. This refinement will come later, most likely when I port this to MicroPython.<\/p>\n\n\n\n<p>More resources:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2023\/06\/SYN6988-front.jpg\">Board front image<\/a> (labelled <em>YS-V6E V1.02<\/em>)<\/li>\n\n\n\n<li><a href=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2023\/06\/SYN6988-back.jpg\">Board back image<\/a><\/li>\n\n\n\n<li>Auto-translated programming manual (thanks, Google Translate!): <a href=\"https:\/\/scruss.com\/wordpress\/wp-content\/uploads\/2023\/06\/SYN6988-translated.pdf\">SYN6988-translated.pdf<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve had one of these cheap(ish &#8211; $15) sound modules from AliExpress for a while. I hadn&#8217;t managed to get much out of it before, but I poked about at it a little more and found I was trying to drive the wrong chip. Aha! Makes all the difference. So here&#8217;s a short narration from [&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":"","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,3315],"tags":[3321,2540,2542,1427,3238],"class_list":["post-17227","post","type-post","status-publish","format-standard","hentry","category-computers-suck","category-electronics","tag-aliexpress","tag-python","tag-serial","tag-speech","tag-tts"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pQNZZ-4tR","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17227","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=17227"}],"version-history":[{"count":3,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17227\/revisions"}],"predecessor-version":[{"id":17235,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/posts\/17227\/revisions\/17235"}],"wp:attachment":[{"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/media?parent=17227"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/categories?post=17227"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/scruss.com\/blog\/wp-json\/wp\/v2\/tags?post=17227"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}