2017-05-01 154 views

回答

1

使用intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hin-IND")代替Hindi語言。

試試這個:

import java.util.ArrayList; 
import java.util.Locale; 

import android.app.Activity; 
import android.content.ActivityNotFoundException; 
import android.content.Intent; 
import android.os.Bundle; 
import android.speech.RecognizerIntent; 
import android.view.Menu; 
import android.view.View; 
import android.widget.ImageButton; 
import android.widget.TextView; 
import android.widget.Toast; 

public class MainActivity extends Activity { 

    private TextView txtSpeechInput; 
    private ImageButton btnSpeak; 
    private final int REQ_CODE_SPEECH_INPUT = 100; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     txtSpeechInput = (TextView) findViewById(R.id.txtSpeechInput); 
     btnSpeak = (ImageButton) findViewById(R.id.btnSpeak); 

     btnSpeak.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       promptSpeechInput(); 
      } 
     }); 

    } 

    /** 
    * Showing google speech input dialog 
    * */ 
    private void promptSpeechInput() { 
     Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); 
     intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, 
       RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); 
     intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "hin-IND"); 

     try { 
      startActivityForResult(intent, REQ_CODE_SPEECH_INPUT); 
     } catch (ActivityNotFoundException a) { 
      Toast.makeText(getApplicationContext(), 
        getString(R.string.speech_not_supported), 
        Toast.LENGTH_SHORT).show(); 
     } 
    } 

    /** 
    * Receiving speech input 
    * */ 
    @Override 
    protected void onActivityResult(int requestCode, int resultCode, Intent data) { 
     super.onActivityResult(requestCode, resultCode, data); 

     switch (requestCode) { 
     case REQ_CODE_SPEECH_INPUT: { 
      if (resultCode == RESULT_OK && null != data) { 

       ArrayList<String> result = data 
         .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS); 
       txtSpeechInput.setText(result.get(0)); 
      } 
      break; 
     } 

     } 
    }  
} 

這裏是一個很好tutorial。希望這會有所幫助〜

+0

此程序是否將印度語作爲輸入並以印度語文本(不是英語)提供輸出? –

+0

@JohnsonTummalapalli感謝您接受我的回答。如果它看起來有用,我希望你也會投票贊成。謝謝:) – FAT

+0

沒有得到印地文字體的文本 – Ancee