Optimize speech output
This commit is contained in:
parent
da0089ae1a
commit
4c47de1ad5
|
@ -7,7 +7,7 @@ import android.view.View;
|
|||
import android.widget.ImageView;
|
||||
|
||||
public class LaunchActivity extends AppCompatActivity {
|
||||
ImageView connect;
|
||||
ImageView connect, cancel;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -16,20 +16,38 @@ public class LaunchActivity extends AppCompatActivity {
|
|||
|
||||
setContentView(R.layout.activity_launch);
|
||||
connect = (ImageView) findViewById(R.id.imageView_connect);
|
||||
cancel = (ImageView) findViewById(R.id.imageView_cancel);
|
||||
|
||||
connect.setImageResource(R.drawable.connect_unselect);
|
||||
cancel.setImageResource(R.drawable.cancel_unselect);
|
||||
|
||||
connect.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
connect.setImageResource(R.drawable.connect_select);
|
||||
|
||||
Intent intent = new Intent(LaunchActivity.this,MainActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
||||
cancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
cancel.setImageResource(R.drawable.cancel_select);
|
||||
|
||||
Intent intent = new Intent(Intent.ACTION_MAIN);
|
||||
intent.addCategory(Intent.CATEGORY_HOME);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume(){
|
||||
connect.setImageResource(R.drawable.connect_unselect);
|
||||
cancel.setImageResource(R.drawable.cancel_unselect);
|
||||
super.onResume();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package solidsnek.amadeus_fork;
|
||||
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Intent;
|
||||
import android.graphics.drawable.AnimationDrawable;
|
||||
import android.media.MediaPlayer;
|
||||
|
@ -12,10 +11,10 @@ import android.util.Log;
|
|||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.speech.RecognizerIntent;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Locale;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
|
@ -23,9 +22,30 @@ public class MainActivity extends AppCompatActivity {
|
|||
ImageView kurisu;
|
||||
AnimationDrawable animation;
|
||||
|
||||
private class Mood {
|
||||
public static final int HAPPY = R.drawable.kurisu_9;
|
||||
public static final int PISSED = R.drawable.kurisu_6;
|
||||
public static final int ANNOYED = R.drawable.kurisu_7;
|
||||
public static final int ANGRY = R.drawable.kurisu_10;
|
||||
public static final int BLUSH = R.drawable.kurisu_11;
|
||||
public static final int SIDE = R.drawable.kurisu_12;
|
||||
public static final int SAD = R.drawable.kurisu_3;
|
||||
public static final int NORMAL = R.drawable.kurisu_2;
|
||||
public static final int EYES_CLOSED = R.drawable.kurisu_1;
|
||||
public static final int WINK = R.drawable.kurisu_5;
|
||||
public static final int DISAPPOINTED = R.drawable.kurisu_8;
|
||||
public static final int INDIFFERENT = R.drawable.kurisu_4;
|
||||
}
|
||||
|
||||
/* Don't forget about permission to use audio! */
|
||||
private SpeechRecognizer sr;
|
||||
protected static final int REQ_CODE_SPEECH_INPUT = 1;
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
if (hasFocus) {
|
||||
speak(R.raw.haro, Mood.HAPPY);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
@ -48,6 +68,9 @@ public class MainActivity extends AppCompatActivity {
|
|||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
if (sr != null)
|
||||
sr.destroy();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@ -55,18 +78,17 @@ public class MainActivity extends AppCompatActivity {
|
|||
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.getDefault());
|
||||
intent.putExtra(RecognizerIntent.EXTRA_PROMPT,
|
||||
getString(R.string.speech_prompt));
|
||||
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, "ja-JP");
|
||||
|
||||
sr.startListening(intent);
|
||||
}
|
||||
|
||||
public void play(int raw, int sprite) {
|
||||
public void speak(int raw, int mood) {
|
||||
try {
|
||||
MediaPlayer m = MediaPlayer.create(getApplicationContext(), raw);
|
||||
|
||||
kurisu.setImageResource(sprite);
|
||||
kurisu.setImageResource(mood);
|
||||
|
||||
animation = (AnimationDrawable) kurisu.getDrawable();
|
||||
|
||||
if (m.isPlaying()) {
|
||||
|
@ -75,8 +97,6 @@ public class MainActivity extends AppCompatActivity {
|
|||
m = new MediaPlayer();
|
||||
}
|
||||
|
||||
m.start();
|
||||
|
||||
m.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
|
||||
@Override
|
||||
public void onPrepared(MediaPlayer mp) {
|
||||
|
@ -92,6 +112,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
m.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
|
||||
@Override
|
||||
public void onCompletion(MediaPlayer mp) {
|
||||
mp.release();
|
||||
|
||||
runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
@ -102,6 +124,8 @@ public class MainActivity extends AppCompatActivity {
|
|||
}
|
||||
});
|
||||
|
||||
m.start();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -131,11 +155,15 @@ public class MainActivity extends AppCompatActivity {
|
|||
Log.d(TAG, "onResults " + results);
|
||||
ArrayList data = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
|
||||
str += data.get(0);
|
||||
if (str.equals("hello")) {
|
||||
play(R.raw.haro, R.drawable.kurisu_9);
|
||||
|
||||
String[] greetingArr = new String[]{"ハロー", "おはよう", "こんにちは", "こんばんは"};
|
||||
List<String> greeting = Arrays.asList(greetingArr);
|
||||
|
||||
if (greeting.contains(str)) {
|
||||
speak(R.raw.haro, Mood.HAPPY);
|
||||
}
|
||||
if (str.equals("hey")) {
|
||||
play(R.raw.hai, R.drawable.kurisu_9);
|
||||
if (str.equals("クリス")) {
|
||||
speak(R.raw.hai, Mood.HAPPY);
|
||||
}
|
||||
}
|
||||
public void onPartialResults(Bundle partialResults) {
|
||||
|
|
|
@ -1,19 +0,0 @@
|
|||
package solidsnek.amadeus_fork;
|
||||
|
||||
public class VoiceLine {
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
public int getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
final private String text;
|
||||
final private int state;
|
||||
|
||||
public VoiceLine(String text, int state){
|
||||
this.text = text;
|
||||
this.state = state;
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 245 KiB |
Binary file not shown.
Before Width: | Height: | Size: 115 KiB |
Binary file not shown.
Before Width: | Height: | Size: 426 KiB |
Binary file not shown.
Before Width: | Height: | Size: 890 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.7 MiB |
|
@ -45,4 +45,15 @@
|
|||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentStart="true" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView_cancel"
|
||||
android:layout_width="180.0dip"
|
||||
android:layout_height="40.0dip"
|
||||
android:src="@drawable/cancel_unselect"
|
||||
android:adjustViewBounds="false"
|
||||
android:cropToPadding="false"
|
||||
android:layout_below="@+id/textView_call"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_marginTop="51dp" />
|
||||
|
||||
</RelativeLayout>
|
Loading…
Reference in New Issue