-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspeech.txt
More file actions
68 lines (56 loc) · 2.14 KB
/
speech.txt
File metadata and controls
68 lines (56 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package drawable.gamefonik;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.Image;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.Locale;
public class MainGame extends Activity {
private TextView jawabanTxt;
private String textA;
TextView textView;
SpeechRecognizer mSpeechRecognizer;
Intent mSpeechRecognizerIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_game_act);
jawabanTxt = (TextView) findViewById(R.id.jawabanTxt);
}
public void getSpeechInput(View view){
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,Locale.getDefault());
if(intent.resolveActivity(getPackageManager())!=null) {
startActivityForResult(intent, 10);
} else {
Toast.makeText(this, "Perangkat anda tidak mendukung", Toast.LENGTH_SHORT).show();
}
}
protected void onActivityResult(int requestCode,int resultCode, Intent data){
super.onActivityResult(requestCode, resultCode,data);
switch (requestCode){
case 10:
if ((resultCode == RESULT_OK &&data != null)) {
ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
jawabanTxt.setText(result.get(0));
}
break;
}
}
}