语音到文本在土耳其语中不起作用

时间:2018-06-07 13:12:08

标签: android speech-to-text

我需要添加我的项目语音搜索。这是我的代码:

public class MainActivity extends AppCompatActivity {
    EditText ed;
    TextView tv;
    Locale locale  = new Locale ("tr", "TR");
    private static final int REQUEST_CODE_SPEECH_INPUT = 100;
    Button speak;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        speak = (Button) findViewById(R.id.speakButton);
        ed = (EditText) this.findViewById(R.id.editText1);
        tv = (TextView) this.findViewById(R.id.textView1);
        speak.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                btnToOpenMic();
            }
        });
    }
    private void btnToOpenMic () {
        Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);

        intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, locale);
        intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Speak...");

        try{
            startActivityForResult(intent, REQUEST_CODE_SPEECH_INPUT);

        } catch (ActivityNotFoundException tim) {

        }
    }
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        switch (requestCode) {
            case REQUEST_CODE_SPEECH_INPUT: {
                if(resultCode == RESULT_OK && null != data) {
                    ArrayList<String> voiceInText = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                    ed.setText(voiceInText.get(0));

                }
                break;
            }
        }
    }
} 

但是当我用土耳其语说些什么的话,我会在编辑文本上得到英语结果(英语单词类似于我在土耳其语中的说法)。为什么会这样?我将语言环境设置为土耳其语。拜托,帮我解决这个问题。

0 个答案:

没有答案