从用户那里获取语音并启动特定服务
Take speech from user and start specific service
这就是我想要做的,我已经指定了一个触发词,现在我想让我的应用程序做的是听取用户的意见,将该输入转换成一个字符串,然后将该字符串与我的触发词字符串进行比较如果它们匹配,那么我的应用程序应该将我们带到消息服务我不知道如何将数组列表转换为字符串请指导我进一步进行。
先感谢您
这是我的代码:
package com.example.ahsan.test;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.widget.Toast;
import java.util.ArrayList;
/**
* Created by ahsan on 5/21/2016.
*/
public class MainActivity extends Activity {
private static final int RESULT_SPEECH = 1;
String trigger="open messaging";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* showing google speech input dialog*/
Intent intent = new Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
try {
startActivityForResult(intent, RESULT_SPEECH);
}
catch (ActivityNotFoundException a) {
Toast t = Toast.makeText(getApplicationContext(),
"Opps! Your device doesn't support Speech to Text",
Toast.LENGTH_SHORT);
t.show();
}
}
/* Receiving speech Input */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> text = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
}
}
}
我想这就是你的意思吧? s
下面是数组中的所有字符串:
for(String s : text){
if(s.matches(trigger){
// We have a match!
break;
}
}
这就是我想要做的,我已经指定了一个触发词,现在我想让我的应用程序做的是听取用户的意见,将该输入转换成一个字符串,然后将该字符串与我的触发词字符串进行比较如果它们匹配,那么我的应用程序应该将我们带到消息服务我不知道如何将数组列表转换为字符串请指导我进一步进行。 先感谢您 这是我的代码:
package com.example.ahsan.test;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.speech.RecognizerIntent;
import android.widget.Toast;
import java.util.ArrayList;
/**
* Created by ahsan on 5/21/2016.
*/
public class MainActivity extends Activity {
private static final int RESULT_SPEECH = 1;
String trigger="open messaging";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
/* showing google speech input dialog*/
Intent intent = new Intent(
RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, "en-US");
try {
startActivityForResult(intent, RESULT_SPEECH);
}
catch (ActivityNotFoundException a) {
Toast t = Toast.makeText(getApplicationContext(),
"Opps! Your device doesn't support Speech to Text",
Toast.LENGTH_SHORT);
t.show();
}
}
/* Receiving speech Input */
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK && null != data) {
ArrayList<String> text = data
.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
}
}
}
我想这就是你的意思吧? s
下面是数组中的所有字符串:
for(String s : text){
if(s.matches(trigger){
// We have a match!
break;
}
}