문제

내 활동에서 Android의 텍스트 음성 변환 기술을 구현하려고 하는데 이상한 오류가 발생합니다.내 코드에서 어떤 소리도 들리지 않습니다.말하기 방법은 onInit 방법에 배치한 경우에만 작동하고 그렇지 않으면 말하지 않습니다.

내 코드는 다음과 같습니다.

public class GameOverActivity extends Activity implements OnInitListener {
private TextToSpeech talker;
....
talker = new TextToSpeech(this, this);  
say("Something",false);
...
   public void onInit(int status) {  
        if (status == TextToSpeech.SUCCESS) {
          talker.setLanguage(Locale.US);
        }
        else if (status == TextToSpeech.ERROR) {
            Toast.makeText(this,"Error occurred while initializing Text-To-Speech engine", Toast.LENGTH_LONG).show();
        }

void say(String text, boolean flush) {
         if(flush == true)
         {
        talker.speak(text,TextToSpeech.QUEUE_FLUSH,null);
         }
         if(flush == false)
         {
        talker.speak(text,TextToSpeech.QUEUE_ADD,null);
         }         
    }

이상한 점은 onInit에 say 메소드를 배치하면 제대로 작동한다는 것입니다!

Logcat을 주의 깊게 관찰한 결과는 다음과 같습니다.

ttsservice.oncreate () tts가로드 중입니다. Audiotrack 시작 ttsservice.setlanguage en-us speech rate를 100으로 설정

그러면 아무 일도 일어나지 않습니다.

위 코드의 문제점이 무엇인지 아시나요?

미리 감사드립니다!

도움이 되었습니까?

해결책

코드를 몇 시간 동안 찾는 후에, 나는 TTS 엔진 초기화가 시간이 걸리게된다는 것을 알게되었다는 것을 알게되었다는 것을 알았습니다.초기화가 끝나지 않으면 Speak 메서드 호출이 실패합니다.

버튼 클릭에 뭔가를 "말하면, 버튼을 누르기 전에 사용자가 생각할 시간이 걸리고 초기화가 끝나고 초기화가 끝나기 때문에 필요하지 않을 것입니다.

곧 초기화가 끝나면 "말하기"를 원하시면이 코드를 사용하십시오.

talker = new TextToSpeech(this, new TextToSpeech.OnInitListener() {

        @Override
        public void onInit(int arg0) {
       if(arg0 == TextToSpeech.SUCCESS) 
           {
        talker.setLanguage(Locale.US);
            say(gameover,true);
            say(line,false);
            say(definition_string,false);
            }
        }
    });
.

다른 팁

구현하는 것이 좋습니다. TextToSpeech.OnInitListener 주요 활동에서.이 시도

public class GameOverActivity extends Activity implements TextToSpeech.OnInitListener {

@Override
public void onInit(int status) {
    if (status == TextToSpeech.SUCCESS) {

        int result = mTts.setLanguage(Locale.US);
        // Try this someday for some interesting results.
        // int result mTts.setLanguage(Locale.FRANCE);
        if (result == TextToSpeech.LANG_MISSING_DATA ||
                result == TextToSpeech.LANG_NOT_SUPPORTED) {
            // Lanuage data is missing or the language is not supported.
            //Log.e(TAG, "Language is not available.");
        } else {
            // Check the documentation for other possible result codes.
            // For example, the language may be available for the locale,
            // but not for the specified country and variant.

            // The TTS engine has been successfully initialized.
            // Allow the user to press the button for the app to speak again.
            // mAgainButton.setEnabled(true);
            // Greet the user.
            //sayHello();
        }
    } else {
        // Initialization failed.

    }

}

private TextToSpeech mTts;
}

이 문제의 또 다른 원인은 TTS 엔진 일 수 있으며, 때로는 삼성 전화에서 기본 TTS 엔진이 페르시아어와 같은 일부 언어로 작동하지 않는 삼성 엔진입니다 (나는 페르시아어 텍스트를 의미하지는 않습니다.다시 영어 텍스트를 읽으려고, 여전히 작동하지 않지만 이상하지만 그것은 발생합니다). 해결하기 위해서는 코드에서 TTS 엔진을 설정하는 것입니다 (또는 수동으로 Setting -> Language input -> Text to speech -> Google Text-to-speech를 선택하십시오)

텍스트 - 음성으로 사용한 문제 하나는 SD 카드에 설치된 경우 USB가 연결되면 작동하지 않습니다.따라서 USB에서 테스트 장치의 플러그를 뽑고 문제를 해결하는지 확인하십시오.

시도 할 수있는 또 다른 일은 프로그램을 통해 스테핑하고 사고로 어떤 방식 으로든 텍스트 - 음성 개체를 변경하는지 확인하고 있습니다.코드의 대화 부분에 중단 점을 설정하고 화자 개체의 모든 변수를 살펴보십시오.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top