Text 语音到文本和语言翻译应用程序(我希望你定期听我说)

Text 语音到文本和语言翻译应用程序(我希望你定期听我说),text,translation,speech,Text,Translation,Speech,我做了一个演讲到文本的应用程序。同时语言翻译应用程序正在做。在与应用程序交谈后,我想定期听我讲话。我应该为此做些什么?我分享应用程序的代码。谢谢 public class MainActivity extends ActionBarActivity { protected static final int RESULT_SPEECH = 1; TextView output; EditText input; ImageButton speak; String out; @Override p

我做了一个演讲到文本的应用程序。同时语言翻译应用程序正在做。在与应用程序交谈后,我想定期听我讲话。我应该为此做些什么?我分享应用程序的代码。谢谢

public class MainActivity extends ActionBarActivity {
protected static final int RESULT_SPEECH = 1;
TextView output;
EditText input;

ImageButton speak;
String out;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    input = (EditText) findViewById(R.id.InputText);
    output = (TextView) findViewById(R.id.OutputText);
    speak = (ImageButton) findViewById(R.id.SpeakButton);
    speak.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(
                    RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
            intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");

            try {
                startActivityForResult(intent, RESULT_SPEECH);
                input.setText("");
            } catch (ActivityNotFoundException a) {
                Toast.makeText(getApplicationContext(), "Olmadı.",
                        Toast.LENGTH_SHORT).show();
            }

        }

    });


}


@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    if (id == R.id.action_settings) {
        return true;
    }
    return super.onOptionsItemSelected(item);
}
方法:

protected void onActivityResult(int requestCode,int resultCode,Intent data){
    super.onActivityResult(requestCode,resultCode,data);
    while(requestCode == RESULT_SPEECH)
    {
        if(resultCode == RESULT_OK && null != data )
        {
            ArrayList<String> text = data
                    .getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);

            input.setText(text.get(0));
            Log.d("deneme", text.toString());
            Log.d("deneme12",data.toString());
        }
        break;
    }

            new AsyncCaller().execute();


}

private class AsyncCaller extends AsyncTask<Void,Void,Void> {

    protected void onPreExecute() {

    }
    @Override
    protected Void doInBackground(Void... params) {
        try {
            out = translate(input.getText().toString());
        } catch (IOException e) {
            e.printStackTrace();
            Log.e("Hata",e.getLocalizedMessage());
        }
        return null;
    }
    protected void onPostExecute(Void result) {
        output.setText(out);
    }

}

public static String translate(String text) throws IOException {

    URL url = new URL(
            "http://translate.google.com.tw/translate_a/t?client=t&hl=en&sl=tr&tl=en&ie=UTF-8&oe=UTF-8&multires=1&oc=1&otf=2&ssel=0&tsel=0&sc=1&q="
                    + URLEncoder.encode(text, "UTF-8"));
    URLConnection urlConnection = url.openConnection();
    urlConnection.setRequestProperty("User-Agent", "Something Else");
    BufferedReader br = new BufferedReader(new InputStreamReader(
            urlConnection.getInputStream()));
    String result = br.readLine();
    br.close();

    result = result.substring(2, result.indexOf("]]") + 1);
    StringBuilder sb = new StringBuilder();
    String[] splits = result.split("(?<!\\\\)\"");
    for (int i = 1; i < splits.length; i += 8)
        sb.append(splits[i]);
    return sb.toString().replace("\\n", "\n").replaceAll("\\\\(.)", "$1");
}
activityresult上受保护的void(int-requestCode、int-resultCode、Intent-data){
super.onActivityResult(请求代码、结果代码、数据);
while(requestCode==结果\语音)
{
if(resultCode==RESULT\u OK&&null!=数据)
{
ArrayList文本=数据
.getStringArrayListExtra(识别器意图.额外结果);
input.setText(text.get(0));
Log.d(“deneme”,text.toString());
Log.d(“deneme12”,data.toString());
}
打破
}
新建AsyncCaller().execute();
}
私有类AsyncCaller扩展了AsyncTask{
受保护的void onPreExecute(){
}
@凌驾
受保护的Void doInBackground(Void…参数){
试一试{
out=translate(input.getText().toString());
}捕获(IOE异常){
e、 printStackTrace();
Log.e(“Hata”,e.getLocalizedMessage());
}
返回null;
}
受保护的void onPostExecute(void结果){
output.setText(输出);
}
}
公共静态字符串转换(字符串文本)引发IOException{
URL=新URL(
"http://translate.google.com.tw/translate_a/t?client=t&hl=en&sl=tr&tl=en&ie=UTF-8&oe=UTF-8&multires=1&oc=1&otf=2&ssel=0&tsel=0&sc=1&q=”
+编码(文本,“UTF-8”);
URLConnection URLConnection=url.openConnection();
setRequestProperty(“用户代理”、“其他内容”);
BufferedReader br=新的BufferedReader(新的InputStreamReader(
urlConnection.getInputStream());
字符串结果=br.readLine();
br.close();
result=result.substring(2,result.indexOf(“]]”)+1);
StringBuilder sb=新的StringBuilder();
String[]splits=result.split((?)?