{"id":8049,"date":"2020-03-28T10:06:04","date_gmt":"2020-03-28T10:06:04","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=8049"},"modified":"2020-03-28T10:06:04","modified_gmt":"2020-03-28T10:06:04","slug":"text-to-speech-on-mobile-with-xamarin","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/text-to-speech-on-mobile-with-xamarin\/","title":{"rendered":"Text to Speech on mobile with Xamarin"},"content":{"rendered":"<p>Previously I looked at <a href=\"http:\/\/putridparrot.com\/blog\/category\/speech\/\" rel=\"noopener noreferrer\" target=\"_blank\">Speech synthesis in Windows with C#<\/a> but what about speech synthesis on mobile.<\/p>\n<p>Xamarin.Essentials has this covered with the TextToSpeech<a href=\"https:\/\/docs.microsoft.com\/en-us\/xamarin\/essentials\/text-to-speech\" rel=\"noopener noreferrer\" target=\"_blank\">TextToSpeech<\/a> class and is included by default when creating a Xamarin Forms mobile application.<\/p>\n<p>It&#8217;s really simple to add text to speech capabilities, we simply write code such as<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nawait TextToSpeech.SpeakAsync(&quot;Hello World&quot;);\r\n<\/pre>\n<p>As you can see by the use of the <em>await<\/em> keyword (and the standard Async suffix), the <em>SpeakAsync<\/em> method returns a task. It also accepts a cancellation token if you need to cancel mid utterance. There&#8217;s also an overload which accepts <em>SpeechOptions<\/em> which allows us to set the volume, pitch and locale.<\/p>\n<p>The second <em>TextToSpeech<\/em> method is <em>GetLocalesAsync<\/em> which allows is to get a list of supported locales from the device that can then be used within the SpeakAsync method&#8217;s SpeechOptions.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nawait TextToSpeech.GetLocalesAsync();\r\n<\/pre>\n<p><em>Note: It&#8217;s fun listening to the attempts at different accents depending upon the locale.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Previously I looked at Speech synthesis in Windows with C# but what about speech synthesis on mobile. Xamarin.Essentials has this covered with the TextToSpeechTextToSpeech class and is included by default when creating a Xamarin Forms mobile application. It&#8217;s really simple to add text to speech capabilities, we simply write code such as await TextToSpeech.SpeakAsync(&quot;Hello World&quot;); [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3,239,290,92,122],"tags":[],"class_list":["post-8049","post","type-post","status-publish","format-standard","hentry","category-c","category-speech","category-tizen","category-xamarin","category-xamarin-forms"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8049","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=8049"}],"version-history":[{"count":3,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8049\/revisions"}],"predecessor-version":[{"id":8063,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/8049\/revisions\/8063"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=8049"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=8049"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=8049"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}