绑定识别服务失败
bind to recognition service failed
我正在测试 VoiceRecognition.i 已搜索但没有找到任何可行的答案。
这是代码。
import android.content.Intent;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import java.util.List;
public class MainActivity extends AppCompatActivity implements View.OnClickListener, RecognitionListener {
Button button;
SpeechRecognizer speechRecognizer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
speechRecognizer.setRecognitionListener(this);
button.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
private static final int SPEECH_REQUEST_CODE = 0;
// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
this.getPackageName());
speechRecognizer.startListening(intent);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
List<String> results = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
String spokenText = results.get(0);
System.out.println(spokenText);
// Do something with spokenText
}
super.onActivityResult(requestCode, resultCode, data);
}
@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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button:
displaySpeechRecognizer();
break;
}
}
@Override
public void onReadyForSpeech(Bundle params) {
System.out.println("onReadyForSpeech");
}
@Override
public void onBeginningOfSpeech() {
System.out.println("onBeginningOfSpeech");
}
@Override
public void onRmsChanged(float rmsdB) {
System.out.println("onRmsChanged");
}
@Override
public void onBufferReceived(byte[] buffer) {
System.out.println("onBufferReceived");
}
@Override
public void onEndOfSpeech() {
System.out.println("onEndOfSpeech");
}
@Override
public void onError(int error) {
System.out.println("onError");
}
@Override
public void onResults(Bundle results) {
System.out.println("onResults");
}
@Override
public void onPartialResults(Bundle partialResults) {
System.out.println("onPartialResults");
}
@Override
public void onEvent(int eventType, Bundle params) {
System.out.println("onEvent");
}
}
这是布局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="whats up"
android:id="@+id/button"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="94dp" />
</RelativeLayout>
这是清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.byteshaft.voicerecognition" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我收到这个错误
-> "voicerecognition E/SpeechRecognizer﹕ bind to recognition service failed "
也找不到它的任何工作示例。
我只是 运行 遇到了同样的问题,对我来说,问题是我的 phone 上安装了一个没有安装语音搜索的 Cyanogenmod 版本。以下是我的解决步骤:
- 从 this thread in xda-developers 下载 APK 文件。该线程对如何安装该文件进行了高级描述,但分步说明如下。
- 使用命令提示符 (windows) 或 shell window (linux),运行 adb 应用程序位于您的 android sdk/platform-tools文件夹
- 确保它可以通过 运行 命令与您的设备通信
adb devices
如果您的设备未列出,您需要确保 phone 的 USB 驱动程序是正确的。
- 通过adb获取root权限。您可能已经拥有它,但是 运行
adb root
- 通过执行
adb shell
进入phoneshell
- 使用命令
cat /proc/mounts
找到对应于“/system”的/dev 列表。您正在寻找类似 /dev/block/mtdblock4 /system yaffs2 ro, realtime 0 0
. 的内容
- 使用相应的 /dev 条目,使用命令将文件系统重新挂载到 read/write 模式(我使用上面的示例,但模式应该很明显)
mount -o rw,remount /dev/block/mtdblock4
。使用命令 exit
输入并退出 adb shell
- 使用推送命令将 apk 从您的计算机复制到您的 phone:
adb push C:\VoiceSearch.apk system/app
- 使用
adb shell
返回到 adb shell 并使用 mount -o ro,remount /dev/block/mtdblock4
并退出 shell.
就是这样。无需重启。您可以通过常规 Google 搜索并点击微型 phone 按钮查看它是否启动来测试它。
如果您运行在模拟器中,它没有语音识别功能。
将语音输入设置(请参阅屏幕截图)中的 "Enhanced Google services" 更改为基本:
voice inout settings
有时语音识别在旧设备上不可用。
检查 this condition 是否 "a speech recognition service is available on the system."
从API 30级需要添加<queries>
for android.speech.RecognitionService
to AndroidManifest.xml
<queries>
<intent>
<action android:name="android.speech.RecognitionService" />
</intent>
</queries>
我正在测试 VoiceRecognition.i 已搜索但没有找到任何可行的答案。 这是代码。
import android.content.Intent;
import android.speech.RecognitionListener;
import android.speech.RecognizerIntent;
import android.speech.SpeechRecognizer;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import java.util.List;
public class MainActivity extends AppCompatActivity implements View.OnClickListener, RecognitionListener {
Button button;
SpeechRecognizer speechRecognizer;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = (Button) findViewById(R.id.button);
speechRecognizer = SpeechRecognizer.createSpeechRecognizer(getApplicationContext());
speechRecognizer.setRecognitionListener(this);
button.setOnClickListener(this);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
private static final int SPEECH_REQUEST_CODE = 0;
// Create an intent that can start the Speech Recognizer activity
private void displaySpeechRecognizer() {
Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_PREFERENCE, "en");
intent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE,
this.getPackageName());
speechRecognizer.startListening(intent);
}
@Override
protected void onActivityResult(int requestCode, int resultCode,
Intent data) {
if (requestCode == SPEECH_REQUEST_CODE && resultCode == RESULT_OK) {
List<String> results = data.getStringArrayListExtra(
RecognizerIntent.EXTRA_RESULTS);
String spokenText = results.get(0);
System.out.println(spokenText);
// Do something with spokenText
}
super.onActivityResult(requestCode, resultCode, data);
}
@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();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button:
displaySpeechRecognizer();
break;
}
}
@Override
public void onReadyForSpeech(Bundle params) {
System.out.println("onReadyForSpeech");
}
@Override
public void onBeginningOfSpeech() {
System.out.println("onBeginningOfSpeech");
}
@Override
public void onRmsChanged(float rmsdB) {
System.out.println("onRmsChanged");
}
@Override
public void onBufferReceived(byte[] buffer) {
System.out.println("onBufferReceived");
}
@Override
public void onEndOfSpeech() {
System.out.println("onEndOfSpeech");
}
@Override
public void onError(int error) {
System.out.println("onError");
}
@Override
public void onResults(Bundle results) {
System.out.println("onResults");
}
@Override
public void onPartialResults(Bundle partialResults) {
System.out.println("onPartialResults");
}
@Override
public void onEvent(int eventType, Bundle params) {
System.out.println("onEvent");
}
}
这是布局。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">
<TextView android:text="@string/hello_world" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textView" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="whats up"
android:id="@+id/button"
android:layout_below="@+id/textView"
android:layout_centerHorizontal="true"
android:layout_marginTop="94dp" />
</RelativeLayout>
这是清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.byteshaft.voicerecognition" >
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
我收到这个错误 -> "voicerecognition E/SpeechRecognizer﹕ bind to recognition service failed " 也找不到它的任何工作示例。
我只是 运行 遇到了同样的问题,对我来说,问题是我的 phone 上安装了一个没有安装语音搜索的 Cyanogenmod 版本。以下是我的解决步骤:
- 从 this thread in xda-developers 下载 APK 文件。该线程对如何安装该文件进行了高级描述,但分步说明如下。
- 使用命令提示符 (windows) 或 shell window (linux),运行 adb 应用程序位于您的 android sdk/platform-tools文件夹
- 确保它可以通过 运行 命令与您的设备通信
adb devices
如果您的设备未列出,您需要确保 phone 的 USB 驱动程序是正确的。 - 通过adb获取root权限。您可能已经拥有它,但是 运行
adb root
- 通过执行
adb shell
进入phoneshell
- 使用命令
cat /proc/mounts
找到对应于“/system”的/dev 列表。您正在寻找类似/dev/block/mtdblock4 /system yaffs2 ro, realtime 0 0
. 的内容
- 使用相应的 /dev 条目,使用命令将文件系统重新挂载到 read/write 模式(我使用上面的示例,但模式应该很明显)
mount -o rw,remount /dev/block/mtdblock4
。使用命令exit
输入并退出 adb shell
- 使用推送命令将 apk 从您的计算机复制到您的 phone:
adb push C:\VoiceSearch.apk system/app
- 使用
adb shell
返回到 adb shell 并使用mount -o ro,remount /dev/block/mtdblock4
并退出 shell.
就是这样。无需重启。您可以通过常规 Google 搜索并点击微型 phone 按钮查看它是否启动来测试它。
如果您运行在模拟器中,它没有语音识别功能。
将语音输入设置(请参阅屏幕截图)中的 "Enhanced Google services" 更改为基本:
voice inout settings
有时语音识别在旧设备上不可用。 检查 this condition 是否 "a speech recognition service is available on the system."
从API 30级需要添加<queries>
for android.speech.RecognitionService
to AndroidManifest.xml
<queries>
<intent>
<action android:name="android.speech.RecognitionService" />
</intent>
</queries>