Search code examples
c#androidvisual-studioxamarin.formsgoogle-text-to-speech

Google text to speech not working C# Android


I am using google text-speech to convert my text to speech on a button click, it works fine when I set manually text like

var textview = FindViewById<TextView>(Resource.Id.textView);
            textview.Text = "anuthing to speak";

but when i set textview text from my following function it says nothing

public string CovertChapterToText(EpubChapter chapter)
        {
            HtmlDocument htmlDocument = new HtmlDocument();
            htmlDocument.LoadHtml(chapter.HtmlContent);
            StringBuilder sb = new StringBuilder();
            foreach (HtmlNode node in htmlDocument.DocumentNode.SelectNodes("//text()"))
            {
                sb.AppendLine(node.InnerText.Trim());
            }
            string chapterText = sb.ToString();
            return chapterText;
        }

like

    textview.Text = CovertChapterToText(chapterToBeShown);

button click event

 btnSpeak.Click += delegate {

                    // if there is nothing to say, don't say it
                    if (!string.IsNullOrEmpty(textview.Text))
                        textToSpeech.Speak(textview.Text, QueueMode.Flush, null);

            };

Solution

  • Don't know why. But google tts donot reads text that was out of screen. When i remove some characters from end it started to work like charm