gpt4 book ai didi

android - SearchView 语音识别器不转录文本

转载 作者:行者123 更新时间:2023-11-29 01:39:40 25 4
gpt4 key购买 nike

我设置了一个简单的 Android 项目,其中一个 Activity 包含启用了语音搜索的 SearchView。当我使用语音搜索功能时,内置语音识别器按预期显示,但它不会在识别器对话框或 SearchView 小部件本身中转录语音文本。但是,它确实通过 SEARCH Intent 正确发送了语音文本,因此可以执行搜索。这是我的项目的源代码和 XML:

AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="searchtest.screens"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/app_id" />

<activity
android:name="searchtest.screens.MainScreen"
android:label="@string/app_name"
android:launchMode="singleTop" >
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable_deal" />
</activity>
</application>

</manifest>

searchable_deal.xml

<searchable xmlns:android="http://schemas.android.com/apk/res/android"
android:hint="@string/search_deals_hint"
android:label="@string/app_name"
android:voiceLanguageModel="web_search"
android:voiceSearchMode="showVoiceSearchButton|launchRecognizer" >
</searchable>

main_screen.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/dealScreenLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >

<LinearLayout
android:id="@+id/searchLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >

<SearchView
android:id="@+id/dealSearch"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="3"
android:hint="@string/search_deals_hint" >
</SearchView>
</LinearLayout>

<ListView
android:id="@+id/dealList"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".8" >
</ListView>
</LinearLayout>

主屏幕.java

public class MainScreen extends Activity implements OnItemClickListener {

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_screen);

setupSearchView();
}

@Override
public void onResume() {
super.onResume();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// use an inflater to populate the ActionBar with items
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.view_deals, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {

return true;
}

@Override
protected void onNewIntent(Intent intent) {

if (Intent.ACTION_SEARCH.equals(intent.getAction())) {

String query = intent.getStringExtra(SearchManager.QUERY);
doSearch(query);
}
}

private void setupSearchView() {
SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE);
final SearchView searchView = (SearchView) findViewById(R.id.dealSearch);
SearchableInfo searchableInfo = searchManager.getSearchableInfo(getComponentName());
searchView.setSearchableInfo(searchableInfo);
searchView.setIconifiedByDefault(false);
}

private void doSearch(String query) {

Toast.makeText(this, "Searching for: " + query, Toast.LENGTH_LONG).show();
}

@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

Toast.makeText(this, "Selected item: " + position, Toast.LENGTH_LONG).show();
}
}

最佳答案

请阅读以下注意事项:

Note: Carefully consider whether voice search is appropriate for your application. All searches performed with the voice search button are immediately sent to your searchable activity without a chance for the user to review the transcribed query. Sufficiently test the voice recognition and ensure that it understands the types of queries that the user might submit inside your application.

http://developer.android.com/guide/topics/search/search-dialog.html#VoiceSearch

关于android - SearchView 语音识别器不转录文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25584595/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com