2017-11-26 7 views
1

デバイスにインストールされているすべての音声を繰り返し処理したいと思います。それは時代遅れだにもかかわらず、私が見TextSoSpeechメタデータでICollectionを繰り返してください

namespace Android.Speech.Tts 
{ 
    public class TextToSpeech : Java.Lang.Object 
    { 
     [Obsolete("deprecated")] 
     public virtual ICollection<Voice> Voices { get; } 

があることを、私は「パブリック仮想いるICollection声{取得し;}」を使用したいと思います。

Xamarinでインストールされた音声を取得する方法は他にありません。

しかし、ICollectionを繰り返したことはありません。

どうすればよいですか?

は私が

ICollection<Voice>nVoices = Android.Speech.Tts.TextToSpeech. 

しかし、 ".Voices" で始まるしようとしたその名前空間の一部ではありません。

+0

) ' – Jason

答えて

1

Voicesは静的なプロパティではないため、反復するにはTextToSpeechクラスのインスタンスが必要です。しかし1を得るために、あなたはIOnInitListenerインタフェースを実装する必要があります:あなたの活動から次に

public class Speaker : Java.Lang.Object, TextToSpeech.IOnInitListener 
{ 
    private readonly TextToSpeech speaker; 

    public Speaker(Context context) 
    { 
     speaker = new TextToSpeech(context, this); 
     // Don't use speaker.Voices here because it hasn't 
     // been initialized. Wait for OnInit to be called. 
    } 

    public void OnInit(OperationResult status) 
    { 
     if (status.Equals(OperationResult.Success)) 
     { 
      // Iterating the collection with a foreach 
      // is perfectly fine. 
      foreach (var voice in speaker.Voices) 
      { 
       // Do whatever with the voice 
      } 
     } 
    } 
} 

を、あなたはそれが好きで使用することができます:あなただけのコレクションで `foreachの(VAR xを使用することができます

var speaker = new Speaker(this); 
関連する問題