{"id":3171,"date":"2021-06-22T12:30:54","date_gmt":"2021-06-22T10:30:54","guid":{"rendered":"https:\/\/www.pschatzmann.ch\/home\/?p=3171"},"modified":"2022-02-16T19:43:11","modified_gmt":"2022-02-16T18:43:11","slug":"text-to-speach-in-arduino","status":"publish","type":"post","link":"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/","title":{"rendered":"Text To Speach in Arduino using SAM"},"content":{"rendered":"<p>I started to look into the topic of <a href=\"https:\/\/en.wikipedia.org\/wiki\/Speech_synthesis\">Text to Speach Synthesis (TTS)<\/a> on Microcontrollers with the final goal to compare different engines.<\/p>\n<p>Since I don&#8217;t want to be bothered to connect the Microcontroller to any output device, I decided to just render the result to a <strong>Webbrowser<\/strong> with an ESP32 before committing to any solution.<\/p>\n<p>Unfortunately there are no Arduino engines which would provide the result as a stream, so I started to &#8220;extend&#8221; some projects. The <strong>first solution<\/strong> is <a href=\"https:\/\/github.com\/pschatzmann\/arduino-SAM\">&#8220;SAM&#8221;<\/a>:<\/p>\n<p>I created this project with the intention to provide SAM as Arduino Library which provides a simple API and supports different output alternatives:<\/p>\n<ul>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-SAM\/blob\/main\/examples\/text_to_speach_callback\/text_to_speach_callback.ino\">Output with a callback method<\/a><\/li>\n<li><a href=\"https:\/\/github.com\/pschatzmann\/arduino-SAM\/blob\/main\/examples\/text_to_speach_stream\/text_to_speach_stream.ino\">Output to a Arduino Stream<\/a><\/li>\n<\/ul>\n<p>SAM is a very small Text-To-Speech (TTS) program written in C, that runs on most popular platforms. It is an adaption to C of the speech software SAM (Software Automatic Mouth) for the Commodore C64 published in the year 1982 by Don&#8217;t Ask Software (now SoftVoice, Inc.). It includes a Text-To-Phoneme converter called reciter and a Phoneme-To-Speech routine for the final output. It is so small that it will work also on embedded computers.<\/p>\n<p>The <strong>Arduino sketch<\/strong> for the <strong>Webserver<\/strong> is quite small because I am using my <a href=\"https:\/\/github.com\/pschatzmann\/arduino-audio-tools\">arduino-audio-tools <\/a>. SAM is directly writing to the WebClient stream in a callback:<\/p>\n<pre><code>#include \"AudioServer.h\"\n#include \"sam_arduino.h\"\n\nusing namespace audio_tools;  \n\nAudioWAVServer server(\"ssid\",\"password\");\nint channels = 1;\nint bits_per_sample = 8;\n\n\/\/ Callback which provides the audio data \nvoid outputData(Stream &amp;out){\n  Serial.print(\"providing data...\");\n  SAM sam(out,  false);\n  sam.setOutputChannels(channels);\n  sam.setOutputBitsPerSample(bits_per_sample);\n  sam.say(\"hallo, I am SAM\");\n}\n\nvoid setup(){\n  Serial.begin(115200);\n  \/\/ start data sink - provide a callback\n  server.begin(outputData, SAM::sampleRate(), channels, bits_per_sample);\n}\n\n\n\/\/ Arduino loop  \nvoid loop() {\n  \/\/ Handle new connections\n  server.doLoop();  \n}\n<\/code><\/pre>\n<p>Well the result did take quite some time (23 sec) to generate and it does not sound great:<br \/>\n<audio class=\"wp-audio-shortcode\" id=\"audio-3171-1\" preload=\"none\" style=\"width: 100%;\" controls=\"controls\"><source type=\"audio\/wav\" src=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/11\/sam.wav?_=1\" \/><a href=\"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/11\/sam.wav\">https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2021\/11\/sam.wav<\/a><\/audio><\/p>\n<p>I am afraid that this slowness is preventing I2S from working&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I started to look into the topic of Text to Speach Synthesis (TTS) on Microcontrollers with the final goal to compare different engines. Since I don&#8217;t want to be bothered to connect the Microcontroller to any output device, I decided to just render the result to a Webbrowser with an [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","_exactmetrics_skip_tracking":false,"_exactmetrics_sitenote_active":false,"_exactmetrics_sitenote_note":"","_exactmetrics_sitenote_category":0,"footnotes":""},"categories":[20,22,35],"tags":[27],"class_list":["post-3171","post","type-post","status-publish","format-standard","hentry","category-arduino","category-machine-sound","category-text-to-speech","tag-tts"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Text To Speach in Arduino using SAM - Phil Schatzmann<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Text To Speach in Arduino using SAM - Phil Schatzmann\" \/>\n<meta property=\"og:description\" content=\"I started to look into the topic of Text to Speach Synthesis (TTS) on Microcontrollers with the final goal to compare different engines. Since I don&#8217;t want to be bothered to connect the Microcontroller to any output device, I decided to just render the result to a Webbrowser with an [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/\" \/>\n<meta property=\"og:site_name\" content=\"Phil Schatzmann\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-22T10:30:54+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-02-16T18:43:11+00:00\" \/>\n<meta name=\"author\" content=\"pschatzmann\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"pschatzmann\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/06\\\/22\\\/text-to-speach-in-arduino\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/06\\\/22\\\/text-to-speach-in-arduino\\\/\"},\"author\":{\"name\":\"pschatzmann\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"headline\":\"Text To Speach in Arduino using SAM\",\"datePublished\":\"2021-06-22T10:30:54+00:00\",\"dateModified\":\"2022-02-16T18:43:11+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/06\\\/22\\\/text-to-speach-in-arduino\\\/\"},\"wordCount\":263,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"keywords\":[\"TTS\"],\"articleSection\":[\"Arduino\",\"Machine Sound\",\"Text To Speech\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/06\\\/22\\\/text-to-speach-in-arduino\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/06\\\/22\\\/text-to-speach-in-arduino\\\/\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/06\\\/22\\\/text-to-speach-in-arduino\\\/\",\"name\":\"Text To Speach in Arduino using SAM - Phil Schatzmann\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\"},\"datePublished\":\"2021-06-22T10:30:54+00:00\",\"dateModified\":\"2022-02-16T18:43:11+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/06\\\/22\\\/text-to-speach-in-arduino\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/06\\\/22\\\/text-to-speach-in-arduino\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/2021\\\/06\\\/22\\\/text-to-speach-in-arduino\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Text To Speach in Arduino using SAM\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#website\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/\",\"name\":\"Phil Schatzmann Consulting\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/home\\\/#\\\/schema\\\/person\\\/73a53638a4e34e8373405fd737dac9b1\",\"name\":\"pschatzmann\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"url\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"contentUrl\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\",\"width\":305,\"height\":305,\"caption\":\"pschatzmann\"},\"logo\":{\"@id\":\"https:\\\/\\\/www.pschatzmann.ch\\\/wp-content\\\/uploads\\\/2022\\\/08\\\/pschatzmann.png\"}}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Text To Speach in Arduino using SAM - Phil Schatzmann","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/","og_locale":"en_US","og_type":"article","og_title":"Text To Speach in Arduino using SAM - Phil Schatzmann","og_description":"I started to look into the topic of Text to Speach Synthesis (TTS) on Microcontrollers with the final goal to compare different engines. Since I don&#8217;t want to be bothered to connect the Microcontroller to any output device, I decided to just render the result to a Webbrowser with an [&hellip;]","og_url":"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/","og_site_name":"Phil Schatzmann","article_published_time":"2021-06-22T10:30:54+00:00","article_modified_time":"2022-02-16T18:43:11+00:00","author":"pschatzmann","twitter_card":"summary_large_image","twitter_misc":{"Written by":"pschatzmann","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/#article","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/"},"author":{"name":"pschatzmann","@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"headline":"Text To Speach in Arduino using SAM","datePublished":"2021-06-22T10:30:54+00:00","dateModified":"2022-02-16T18:43:11+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/"},"wordCount":263,"commentCount":1,"publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"keywords":["TTS"],"articleSection":["Arduino","Machine Sound","Text To Speech"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/","url":"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/","name":"Text To Speach in Arduino using SAM - Phil Schatzmann","isPartOf":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#website"},"datePublished":"2021-06-22T10:30:54+00:00","dateModified":"2022-02-16T18:43:11+00:00","breadcrumb":{"@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.pschatzmann.ch\/home\/2021\/06\/22\/text-to-speach-in-arduino\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pschatzmann.ch\/home\/"},{"@type":"ListItem","position":2,"name":"Text To Speach in Arduino using SAM"}]},{"@type":"WebSite","@id":"https:\/\/www.pschatzmann.ch\/home\/#website","url":"https:\/\/www.pschatzmann.ch\/home\/","name":"Phil Schatzmann Consulting","description":"","publisher":{"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pschatzmann.ch\/home\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.pschatzmann.ch\/home\/#\/schema\/person\/73a53638a4e34e8373405fd737dac9b1","name":"pschatzmann","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","url":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","contentUrl":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png","width":305,"height":305,"caption":"pschatzmann"},"logo":{"@id":"https:\/\/www.pschatzmann.ch\/wp-content\/uploads\/2022\/08\/pschatzmann.png"}}]}},"post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/comments?post=3171"}],"version-history":[{"count":31,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3171\/revisions"}],"predecessor-version":[{"id":3798,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/posts\/3171\/revisions\/3798"}],"wp:attachment":[{"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/media?parent=3171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/categories?post=3171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pschatzmann.ch\/home\/wp-json\/wp\/v2\/tags?post=3171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}