2010-11-13 31 views
2

我使用谷歌transalate API在我的應用程序的音頻文件類似谷歌翻譯聽着,我在文本轉換所做的是確定 但翻譯文本到語音掛起如何實現轉換的文本語音在Android的

http://android-developers.blogspot.com/2009/09/introduction-to-text-to-speech-in.html

這段代碼我正在使用如何在android中實現翻譯文本語音。

http://www.freeimagehosting.net/uploads/c382dd10f8.png 這上面的截圖中顯示的文本轉換爲確定,單擊audiobutton圖像收聽audioplayer如何能實現

我的代碼 //音頻按鈕單擊事件..........

翻譯文本
 submit = (ImageView) findViewById(R.id.ImageView01); 
      submit.setOnClickListener(new View.OnClickListener() 
      { public void onClick(View v) 
      { 
       //speech code how can implemented 
        } 
      }); 


    /////////////////// translate button code////////////////////// 
((Button)findViewById(R.id.Button01)).setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       try { 
        String fromLan=spineFrom.getSelectedItem().toString(); 
        String toLan=spineTo.getSelectedItem().toString(); 
       Log.v("check",fromLan+" :"+toLan); 
        translatedText = Translate.execute(((EditText)findViewById(R.id.EditText01)).getText().toString(),converStrtoLan(fromLan),converStrtoLan(toLan)); 
         ((TextView)findViewById(R.id.TextView02)).setText(translatedText); 
         Intent checkIntent = new Intent(); 
         checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); 
         startActivityForResult(checkIntent,1); 

       } catch (Exception e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 

      } 
     }); 
    } 
    private TextToSpeech mTts; 
    protected void onActivityResult(
      int requestCode, int resultCode, Intent data) { 
     if (requestCode == 1) { 
      if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) { 
       // success, create the TTS instance 
       mTts = new TextToSpeech(this, null); 
      } else { 
       // missing data, install it 
       Intent installIntent = new Intent(); 
       installIntent.setAction(
        TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA); 
       startActivity(installIntent); 
      } 
     } 
     mTts.setLanguage(Locale.US); 
     String myText1 = "Did you sleep well?"; 
     String myText2 = "I hope so, because it's time to wake up."; 
     mTts.speak(myText1, TextToSpeech.QUEUE_FLUSH, null); 
     mTts.speak(myText2, TextToSpeech.QUEUE_ADD, null); 
    } 
    private Language converStrtoLan(String lan){ 
     if(lan.equals("ENGLISH") || lan=="ENGLISH"){ 
      return Language.ENGLISH; 
     }else if (lan.equals("SPANISH") || lan=="SPANISH"){ 
      return Language.SPANISH; 
     } 

     return null; 
    } 
} 

如何在音頻click事件添加此音頻編碼, 請轉發此代碼這個問題我爲更多的數量在此先感謝天的鬥爭的一些有價值的反應..

+0

請僅在代碼塊中插入代碼片段。 – Keshan 2010-11-13 11:43:16

+0

對不起先生更改代碼塊內的代碼片段請先轉發我的問題是轉換語音怎麼樣才能在按鈕中點擊點擊 – Narasimha 2010-11-13 11:53:26

回答

1

爲了使用Android進行文本到語音,您可以使用eyes-free

+0

對不起先生更改代碼塊內的代碼片段請先轉發我的問題轉換語音怎麼樣才能在按鈕點擊聽取轉換文本的聲音 – Narasimha 2010-11-13 12:16:00

+0

請提前感謝此代碼的一些解決方案 – Narasimha 2010-11-15 04:32:05

+0

其工作感謝您的寶貴迴應 – Narasimha 2010-11-15 06:57:48