能否修改NMAVoicePackage的CountryCode为印尼?Here API导航语音如何切换为印尼语?
Hey there! Let's tackle your two questions about switching navigation voice to Indonesian with the HERE SDK:
1. Can I modify the CountryCode of an existing NMAVoicePackage to Indonesia?
Short answer: No, you can't directly modify the CountryCode (or languageCode) of an existing NMAVoicePackage instance. These properties are tied to the pre-built voice package files provided by HERE, which are optimized for specific regions and languages.
Instead of modifying an existing package, you'll want to retrieve the official Indonesian voice package from the HERE SDK's voice catalog. Each voice package is uniquely identified by its language and country code (Indonesian typically uses languageCode: "id" and countryCode: "ID").
2. How to switch navigation voice to Indonesian when voicePackage.languageCode is read-only?
The languageCode being read-only makes sense—it's a fixed property of the voice package itself. To switch to Indonesian voice guidance, you need to:
- Fetch the Indonesian voice package from the
NMAVoiceCatalog - Download it if it's not already saved locally
- Assign this package to your navigation manager
Here's a quick code example (using Swift for reference) to implement this:
// Access the shared voice catalog let voiceCatalog = NMAVoiceCatalog.sharedInstance() // Loop through available voice packages to find the Indonesian one for voicePackage in voiceCatalog.availableVoicePackages { // Filter for Indonesian (language code "id" or country code "ID") if voicePackage.languageCode == "id" || voicePackage.countryCode == "ID" { // Check if the package is already downloaded if !voicePackage.isDownloaded { // Download the package if needed voiceCatalog.downloadVoicePackage(voicePackage, completion: { error in guard error == nil else { print("Failed to download Indonesian voice package: \(error!)") return } // Set the downloaded package to the maneuver manager NMAManeuverManager.sharedInstance().voicePackage = voicePackage }) } else { // Package is already downloaded—assign it immediately NMAManeuverManager.sharedInstance().voicePackage = voicePackage } break } }
Once you assign the Indonesian voice package to NMAManeuverManager, your turn-by-turn navigation will automatically use Indonesian voice prompts without needing to modify any read-only properties.
内容的提问来源于stack exchange,提问作者Imanuel Pardosi

