2017-11-26 1 views
1

장치에 설치된 모든 음성을 반복하고 싶습니다. 내가ICollection을 통해 반복하십시오.

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

심지어는 쓸모 비록이 있다고 볼 수있는 TextSoSpeech 메타 데이터에

, 나는 "public 가상 ICollection은 음색 {얻을;}"를 사용하고 싶습니다.

저는 Xamarin으로 설치된 음성을 얻는 다른 방법을 모릅니다.

그러나 ICollection을 반복 한 적이 없습니다.

어떻게 완료 될까요?

나는

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

그러나 ".Voices"로 시작하는 노력 해당 네임 스페이스의 일부가 아닙니다.

+0

)' – Jason

답변

1

Voices은 정적 속성이 아니기 때문에 TextToSpeech 클래스의 인스턴스를 반복해야합니다. 하지만 하나를 얻으려면, 당신은 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); 
관련 문제