高德地图之语音导航
Posted ZHZMAREN
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了高德地图之语音导航相关的知识,希望对你有一定的参考价值。
头文件:
#import "iflyMSC/IFlySpeechSynthesizer.h"
#import "iflyMSC/IFlySpeechSynthesizerDelegate.h"
#import "iflyMSC/IFlySpeechConstant.h"
#import "iflyMSC/IFlySpeechUtility.h"
#import "iflyMSC/IFlySetting.h"
配置语音信息!
- (void)configIFlySpeech
[IFlySpeechUtility createUtility:[NSString stringWithFormat:@"appid=%@,timeout=%@",@"56f4c9f0",@"20000"]];
[IFlySetting setLogFile:LVL_NONE];
[IFlySetting showLogcat:NO];
// 设置语音合成的参数
[[IFlySpeechSynthesizer sharedInstance] setParameter:@"30" forKey:[IFlySpeechConstant SPEED]];//合成的语速,取值范围 0~100
[[IFlySpeechSynthesizer sharedInstance] setParameter:@"50" forKey:[IFlySpeechConstant VOLUME]];//合成的音量;取值范围 0~100
// 发音人,默认为”xiaoyan”;可以设置的参数列表可参考个 性化发音人列表;
[[IFlySpeechSynthesizer sharedInstance] setParameter:@"vinn" forKey:[IFlySpeechConstant VOICE_NAME]];
// 音频采样率,目前支持的采样率有 16000 和 8000;
[[IFlySpeechSynthesizer sharedInstance] setParameter:@"8000" forKey:[IFlySpeechConstant SAMPLE_RATE]];
// 当你再不需要保存音频时,请在必要的地方加上这行。
[[IFlySpeechSynthesizer sharedInstance] setParameter:nil forKey:[IFlySpeechConstant TTS_AUDIO_PATH]];
导航信息配置:
[AMapNaviServices sharedServices].apiKey =AMKEY;
管理者
- (void)initNaviManager
if (self.naviManager == nil)
self.naviManager = [[AMapNaviManager alloc] init];
[self.naviManager setDelegate:self];
导航视图
- (void)initNaviViewController
if (self.naviViewController == nil)
self.naviViewController = [[AMapNaviViewController alloc] initWithDelegate:self];
[self.naviViewController setDelegate:self];
语音
- (void)initIFlySpeech
if (self.iFlySpeechSynthesizer == nil)
_iFlySpeechSynthesizer = [IFlySpeechSynthesizer sharedInstance];
_iFlySpeechSynthesizer.delegate = self;
/*!
@brief AMapNaviManager发生错误时的回调函数
@param error 错误信息
*/
- (void)naviManager:(AMapNaviManager *)naviManager error:(NSError *)error;
/*!
@brief naviViewController被展示出来后的回调
@param naviViewController 被展示出来的ViewController
*/
- (void)naviManager:(AMapNaviManager *)naviManager didPresentNaviViewController:(UIViewController *)naviViewController
NSLog(@"didPresentNaviViewController");
[self.naviManager startGPSNavi];
/*!
@brief 驾车路径规划成功后的回调函数
*/
- (void)naviManagerOnCalculateRouteSuccess:(AMapNaviManager *)naviManager
NSLog(@"OnCalculateRouteSuccess");
if (self.naviViewController == nil)
[self initNaviViewController];
[self.naviManager presentNaviViewController:self.naviViewController animated:YES];
/*!
@brief 驾车路径规划失败后的回调函数
@param error 计算路径的错误,error.code参照AMapNaviCalcRouteState
*/
- (void)naviManager:(AMapNaviManager *)naviManager onCalculateRouteFailure:(NSError *)error;
/*!
@brief 导航播报信息回调函数
@param soundString 播报文字
@param soundStringType 播报类型,包含导航播报、前方路况播报和整体路况播报,参考AMapNaviSoundType
*/
- (void)naviManager:(AMapNaviManager *)naviManager playNaviSoundString:(NSString *)soundString soundStringType:(AMapNaviSoundType)soundStringType
NSLog(@"playNaviSoundString:%ld:%@", (long)soundStringType, soundString);
if (soundStringType == AMapNaviSoundTypePassedReminder)
//用系统自带的声音做简单例子,播放其他提示音需要另外配置
AudioservicesPlaySystemSound(1009);
else
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^
if (soundStringType ==1)
NSString *str = [NSString stringWithFormat:@"上海喜 泊 客 约 停 车 为您导航:%@",soundString];
[_iFlySpeechSynthesizer startSpeaking:str];
else
[_iFlySpeechSynthesizer startSpeaking:soundString];
);
#pragma mark - AManNaviViewController Delegate
- (void)naviViewControllerCloseButtonClicked:(AMapNaviViewController *)naviViewController
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^
[_iFlySpeechSynthesizer stopSpeaking];
);
[self.naviManager stopNavi];
[self.naviManager dismissNaviViewControllerAnimated:YES];
- (void)naviViewControllerMoreButtonClicked:(AMapNaviViewController *)naviViewController
if (self.naviViewController.viewShowMode == AMapNaviViewShowModeCarNorthDirection)
self.naviViewController.viewShowMode = AMapNaviViewShowModeMapNorthDirection;
else
self.naviViewController.viewShowMode = AMapNaviViewShowModeCarNorthDirection;
- (void)naviViewControllerTurnIndicatorViewTapped:(AMapNaviViewController *)naviViewController
[self.naviManager readNaviInfoManual];
#pragma mark - iFlySpeechSynthesizer Delegate
- (void)onCompleted:(IFlySpeechError *)error
NSLog(@"Speak Error:%d:%@", error.errorCode, error.errorDesc);
以上是关于高德地图之语音导航的主要内容,如果未能解决你的问题,请参考以下文章