按照HERE Android SDK开发人员导航语音指令指南中的步骤操作,我无法启动语音功能。调试信息如下:
// Retrieve the VoiceCatalog and download the latest updates
VoiceCatalog voiceCatalog = VoiceCatalog.getInstance();
voiceCatalog.downloadCatalog(new VoiceCatalog.OnDownloadDoneListener() {
@Override
public void onDownloadDone(VoiceCatalog.Error error) {
if (error == VoiceCatalog.Error.NONE) {
// catalog download successful
Toast.makeText(getApplicationContext(), "Voice catalog download successful.", Toast.LENGTH_LONG).show();
} else {
Toast.makeText(getApplicationContext(), "Voice catalog download error.", Toast.LENGTH_LONG).show();
}
}
});
onDownloadDone()
函数将始终收到错误:VoiceCatalog.Error UNKNOW
VoiceCatalog.getInstance().isLocalCatalogAvailable()
isLocalCatalogAvailable()
永远都是假的。
有人可以就此问题提出建议吗?感谢。
答案 0 :(得分:2)
我们针对此问题找到了以下解决方案。
private void setupVoice() {
// Retrieve the VoiceCatalog and download the latest updates
VoiceCatalog voiceCatalog = VoiceCatalog.getInstance();
if (!voiceCatalog.isLocalCatalogAvailable()) {
if (DEBUG) Log.d(TAG, "Voice catalog is not available in local storage.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice catalog is not available in local storage.", Toast.LENGTH_LONG).show();
voiceCatalog.downloadCatalog(new VoiceCatalog.OnDownloadDoneListener() {
@Override
public void onDownloadDone(VoiceCatalog.Error error) {
if (error == VoiceCatalog.Error.NONE) {
// catalog download successful
if (DEBUG) Log.d(TAG, "Download voice catalog successfully.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice catalog download successful.", Toast.LENGTH_LONG).show();
} else {
if (DEBUG) Log.d(TAG, "Download voice catalog failed.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice catalog download error.", Toast.LENGTH_LONG).show();
}
// Get the list of voice packages from the voice catalog list
List<VoicePackage> voicePackages =
VoiceCatalog.getInstance().getCatalogList();
if (voicePackages.size() == 0) {
if (DEBUG) Log.d(TAG, "Voice catalog size is 0.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice catalog size is 0.", Toast.LENGTH_LONG).show();
}
long id = -1;
// select
for (VoicePackage voicePackage : voicePackages) {
if (voicePackage.getMarcCode().compareToIgnoreCase("eng") == 0) {
//if (voicePackage.isTts()) // TODO: need to figure out why always return false
{
id = voicePackage.getId();
break;
}
}
}
if (!VoiceCatalog.getInstance().isLocalVoiceSkin(id)) {
final long finalId = id;
VoiceCatalog.getInstance().downloadVoice(id, new VoiceCatalog.OnDownloadDoneListener() {
@Override
public void onDownloadDone(VoiceCatalog.Error error) {
if (error == VoiceCatalog.Error.NONE) {
//voice skin download successful
if (DEBUG) Log.d(TAG, "Download voice skin successfully.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice skin download successful.", Toast.LENGTH_LONG).show();
// set the voice skin for use by navigation manager
if (VoiceCatalog.getInstance().getLocalVoiceSkin(finalId) != null) {
m_navigationManager.setVoiceSkin(VoiceCatalog.getInstance().getLocalVoiceSkin(finalId));
} else {
if (DEBUG) Log.d(TAG, "Get local voice skin error.");
//Toast.makeText(mActivity.getApplicationContext(), "Navi manager set voice skin error.", Toast.LENGTH_LONG).show();
}
} else {
if (DEBUG) Log.d(TAG, "Download voice skin failed.");
//Toast.makeText(mActivity.getApplicationContext(), "Voice skin download error.", Toast.LENGTH_LONG).show();
}
}
});
} else {
// set the voice skin for use by navigation manager
if (VoiceCatalog.getInstance().getLocalVoiceSkin(id) != null) {
m_navigationManager.setVoiceSkin(VoiceCatalog.getInstance().getLocalVoiceSkin(id));
} else {
if (DEBUG) Log.d(TAG, "Get local voice skin error.");
//Toast.makeText(mActivity.getApplicationContext(), "Navi manager set voice skin error.", Toast.LENGTH_LONG).show();
}
}
}
});
}
}
答案 1 :(得分:0)
通过以下步骤对我有用:
像这样更新BasicMapActivity.java(当然用你的命名空间更新com.here.jon.test):
package com.here.jon.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.widget.Toast;
import com.here.android.mpa.common.GeoCoordinate;
import com.here.android.mpa.common.OnEngineInitListener;
import com.here.android.mpa.guidance.VoiceCatalog;
import com.here.android.mpa.guidance.VoiceCatalog.Error;
import com.here.android.mpa.guidance.VoiceCatalog.OnDownloadDoneListener;
import com.here.android.mpa.mapping.Map;
import com.here.android.mpa.mapping.MapFragment;
import com.here.jon.test.R;
public class BasicMapActivity extends Activity {
// map embedded in the map fragment
private Map map = null;
// map fragment embedded in this activity
private MapFragment mapFragment = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Search for the map fragment to finish setup by calling init().
mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.mapfragment);
mapFragment.init(new OnEngineInitListener() {
@Override
public void onEngineInitializationCompleted(OnEngineInitListener.Error error) {
if (error == OnEngineInitListener.Error.NONE) {
// retrieve a reference of the map from the map fragment
map = mapFragment.getMap();
// Set the map center coordinate to the Vancouver region (no animation)
map.setCenter(new GeoCoordinate(49.196261, -123.004773, 0.0), Map.Animation.NONE);
// Set the map zoom level to the average between min and max (no animation)
map.setZoomLevel((map.getMaxZoomLevel() + map.getMinZoomLevel()) / 2);
downloadVoiceCatalog();
} else {
System.out.println("ERROR: Cannot initialize Map Fragment");
}
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
private void downloadVoiceCatalog() {
boolean result = VoiceCatalog.getInstance().downloadCatalog(new OnDownloadDoneListener(){
@Override
public void onDownloadDone(Error error) {
Toast.makeText(getApplicationContext(), "onDownloadDone: " + error.toString(), Toast.LENGTH_LONG).show();
}});
if (result) {
Toast.makeText(this, "Successfully requested catalog", Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(this, "Failed to request catalog", Toast.LENGTH_LONG).show();
}
}
如果你按照这些步骤操作,你应该在onDownloadDone上获得一个Toast:最后没有