如何将音频文件.wav或语音识别转换为文本,Android Studio

时间:2017-05-06 15:12:13

标签: java android audio text

我在google上,在堆栈上搜索了很多网站,但我什么都没发现,我找到了PC的java代码和库,但没有找到android。有人可以帮我吗?

1 个答案:

答案 0 :(得分:-1)

您必须使用谷歌功能文字转语音。

public class MainActivity extends AppCompatActivity {
   TextToSpeech t1;
   EditText ed1;
   Button b1;

   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      ed1=(EditText)findViewById(R.id.editText);
      b1=(Button)findViewById(R.id.button);

      t1=new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() {
         @Override
         public void onInit(int status) {
            if(status != TextToSpeech.ERROR) {
               t1.setLanguage(Locale.UK);
            }
         }
      });

      b1.setOnClickListener(new View.OnClickListener() {
         @Override
         public void onClick(View v) {
            String toSpeak = ed1.getText().toString();
            Toast.makeText(getApplicationContext(), toSpeak,Toast.LENGTH_SHORT).show();
            t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null);
         }
      });
   }

   public void onPause(){
      if(t1 !=null){
         t1.stop();
         t1.shutdown();
      }
      super.onPause();
   }
}
相关问题