c# - How do i use text to speech? -


i'm using xamarin. , android project. created new class , added code:

using system; using android.speech.tts; using system.collections.generic;   namespace app1 {      public class texttospeech_android : java.lang.object, itexttospeech, texttospeech.ioninitlistener     {         texttospeech speaker; string tospeak;         public texttospeech_android() { }          public void speak(string text)         {             var c = forms.context;             tospeak = text;             if (speaker == null)             {                 speaker = new texttospeech(c, this);             }             else             {                 var p = new dictionary<string, string>();                 speaker.speak(tospeak, queuemode.flush, p);                 system.diagnostics.debug.writeline("spoke " + tospeak);             }         }          #region ioninitlistener implementation         public void oninit(operationresult status)         {             if (status.equals(operationresult.success))             {                 system.diagnostics.debug.writeline("speaker init");                 var p = new dictionary<string, string>();                 speaker.speak(tospeak, queuemode.flush, p);             }             else             {                 system.diagnostics.debug.writeline("was quiet");             }         }         #endregion     }  } 

i'm getting errors , warnings:

  1. on line:

    var c = forms.context

forms not exist. forms , how can fix ?

  1. on line:

    public class texttospeech_android : java.lang.object, itexttospeech, texttospeech.ioninitlistener

itexttospeech not exist.

and on both same lines:

speaker.speak(tospeak, queuemode.flush, p); 

i'm getting warning message:

warning 3 'android.speech.tts.texttospeech.speak(string, android.speech.tts.queuemode, system.collections.generic.idictionary)' obsolete: '"deprecated"

what want in program text put in string in program when run program read in voice text in string on phone.

after fixing errors how use class in main activity ?

using system; using android.app; using android.content; using android.runtime; using android.views; using android.widget; using android.os; using android.speech.tts;  namespace app1 {     [activity(label = "app1", mainlauncher = true, icon = "@drawable/icon")]     public class mainactivity : activity     {         int count = 1;            protected override void oncreate(bundle bundle)         {             base.oncreate(bundle);              // set our view "main" layout resource             setcontentview(resource.layout.main);                 // our button layout resource,             // , attach event             button button = findviewbyid<button>(resource.id.mybutton);              button.click += delegate {                 button.text = string.format("{0} clicks!", count++);             };         }       } } 

you should follow , read every part of tutorial you're following.

1) add following statement top of file (texttospeech_android.cs)

using xamarin.forms; 

2) create itexttospeech interface

public interface itexttospeech {     void speak (string text); } 

3) method deprecated, meaning might not exists in future version of android, , therefor should use another method.


Comments

Popular posts from this blog

qt - Using float or double for own QML classes -

Create Outlook appointment via C# .Net -

ios - Swift Array Resetting Itself -