Voice catalog is not available in local storage for Here Maps Voice Instruction feature

浪尽此生 提交于 2021-02-08 10:27:25

问题


Following the steps in HERE Android SDK Developer's Guide for Navigation Voice Instruction, I cannot start the Voice feature. The debug information is as below:

  1. // 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() function will always receive an error: VoiceCatalog.Error UNKNOW

  1. VoiceCatalog.getInstance().isLocalCatalogAvailable()

isLocalCatalogAvailable() will always be false.

  1. A set of sample voice skins from sdk.zip/misc is copied to /data/app_namespace/files/voices-download

Could anyone suggest on this issue? Thanks.


回答1:


We find the following solution for this issue.

     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();
                        }
                    }
                }
            });
        } 
    }



回答2:


It worked for me with these steps:

  1. Apply for 90 day trial here (should receive SDK package, appid, token and license key)
  2. Download and unzip HERE-sdk.zip
  3. Open HERE-sdk/tutorial/BasicMapSolution (I used eclipse)
  4. Refactor BasicMapActivity namespace to my namespace from step 1
  5. Update AndroidManifest.xml with appid, apptoken and license key
  6. Update BasicMapActivity.java like this (updating com.here.jon.test with your namespace of course):

    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();
        }
    }
    

If you follow these steps, you should get a Toast with onDownloadDone: NONE at the end



来源:https://stackoverflow.com/questions/31423524/voice-catalog-is-not-available-in-local-storage-for-here-maps-voice-instruction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!