TTSConfigViewController.m 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. //
  2. // TTSConfigViewController.m
  3. // TTSDemo
  4. //
  5. // Created by lappi on 3/16/16.
  6. // Copyright © 2016 baidu. All rights reserved.
  7. //
  8. #include <math.h>
  9. #import <AVFoundation/AVAudioSession.h>
  10. #import "TTSConfigViewController.h"
  11. #import "BDSSpeechSynthesizer.h"
  12. #import "BDSSpeechSynthesizerParams.h"
  13. enum SettingsSections{
  14. SettingSection_AudioPlayer = 0,
  15. SettingSection_SynthesisGeneral,
  16. SettingSection_OnlineSynthesis,
  17. SettingSectionCount
  18. };
  19. enum SettingRows_AudioPlayer{
  20. SettingRow_AudioPlayer_AudioVolume = 0,
  21. SettingRow_AudioPlayer_Enable_AVAudioSessionManagement,
  22. SettingRow_AudioPlayer_AVAudiosessionCategory,
  23. SettingRow_AudioPlayer_AVAudioSessionCategoryOptions,
  24. SettingRow_AudioPlayerCount,
  25. };
  26. enum SettingRows_SynthesisGeneral{
  27. SettingRow_SynthesisGeneral_SynthVolume = 0,
  28. SettingRow_SynthesisGeneral_SynthSpeed,
  29. SettingRow_SynthesisGeneral_SynthPitch,
  30. SettingRow_SynthesisGeneral_EnableSpeak,
  31. SettingRow_SynthesisGeneral_ReadTextFromFile,
  32. SettingRow_SynthesisGeneral_OnlineThreshold,
  33. SettingRow_SynthesisGeneralCount
  34. };
  35. enum SettingRows_OnlineSynthesis{
  36. SettingRow_OnlineSynthesis_Speaker = 0,
  37. SettingRow_OnlineSynthesis_AudioEncoding,
  38. SettingRow_OnlineXml,
  39. SettingRow_OnlineSynthesisCount
  40. };
  41. enum SettingRows_OfflineSynthesis{
  42. SettingRow_OfflineAudiomodelManager = 0,
  43. SettingRow_OfflineSynthesis_AudioEncoding,
  44. SettingRow_OfflineSynthesis_AppID,
  45. SettingRow_OfflineXml,
  46. SettingRow_OfflineSynthesisCount
  47. };
  48. NSString* const EDIT_PROPERTY_ID_PLAYER_VOLUME = @"PLAYER_VOLUME";
  49. NSString* const EDIT_PROPERTY_ID_VOLUME = @"VOL";
  50. NSString* const EDIT_PROPERTY_ID_SPEED = @"SPEED";
  51. NSString* const EDIT_PROPERTY_ID_PITCH = @"PITC";
  52. NSString* const EDIT_PROPERTY_ID_ENABLE_SPEAK = @"SPEAK";
  53. NSString* const EDIT_PROPERTY_ID_ENABLE_FILE_SYNTH = @"READ_FROM_FILE";
  54. NSString* const EDIT_PROPERTY_ID_ENABLE_AUDIO_SESSION_MANAGEMENT = @"ENABLE_AV_MANAGEMENT";
  55. NSString* const EDIT_PROPERTY_ID_ONLINE_TTS_XML = @"ONLINE_TTS_XML";
  56. NSString* const EDIT_PROPERTY_ID_OFFLINE_TTS_XML = @"OFFLINE_TTS_XML";
  57. NSString* const EDIT_PROPERTY_ID_TTS_ONLINE_TIMEOUT = @"ONLINE_TTS_TIMEOUT";
  58. NSString* const EDIT_PROPERTY_ID_OFFLINE_TTS_APPID = @"OFFLINE_ENGINE_APP_ID";
  59. static float SDK_PLAYER_VOLUME = 0.5;
  60. static NSString* setOfflineAppID = @"";
  61. #define KNOWN_ONLINE_SPEAKER_COUNT 5
  62. #define AVAILABLE_AV_CATEGORY_OPTION_COUNT 5
  63. int AUDIO_SESSION_CATEGORY_OPTIONS[] = {
  64. AVAudioSessionCategoryOptionMixWithOthers,
  65. AVAudioSessionCategoryOptionDuckOthers,
  66. AVAudioSessionCategoryOptionAllowBluetooth,
  67. AVAudioSessionCategoryOptionDefaultToSpeaker,
  68. AVAudioSessionCategoryOptionInterruptSpokenAudioAndMixWithOthers
  69. };
  70. const NSString *AUDIO_SESSION_CATEGORY_OPT_NAMES[] = {@"Mix with others",@"Duck others",@"Allow bluetooth",@"Default to speaker",@"Interrupt spoken, mix others"};
  71. typedef enum SelectionControllerSelectProperty{
  72. SelectionControllerSelectProperty_ONLINE_AUE,
  73. SelectionControllerSelectProperty_AUDIO_SESSION_CATEGORY_OPTIONS,
  74. SelectionControllerSelectProperty_AUDIO_SESSION_CATEGORY,
  75. SelectionControllerSelectProperty_ONLINE_SPEAKER,
  76. SelectionControllerSelectProperty_OFFLINE_AUDIO_ENCODING,
  77. SelectionControllerSelectProperty_ONLINE_TTS_THRESHOLD
  78. }SelectionControllerSelectProperty;
  79. __strong static NSString* currentOfflineEnglishModelName;
  80. __strong static NSString* currentOfflineChineseModelName;
  81. @interface TTSConfigViewController ()
  82. @property (nonatomic,strong)NSMutableArray* selectionControllerSelectedIndexes;
  83. @property (nonatomic)SelectionControllerSelectProperty ongoing_multiselection;
  84. @property (nonatomic,strong)NSArray* audioSessionCategories;
  85. @end
  86. @implementation TTSConfigViewController
  87. - (void)viewDidLoad {
  88. [super viewDidLoad];
  89. self.isAudioSessionManagementEnabled = [[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_ENABLE_AVSESSION_MGMT withError:nil] boolValue];
  90. self.audioSessionCategories = [[NSArray alloc] initWithObjects:AVAudioSessionCategoryAmbient, AVAudioSessionCategorySoloAmbient, AVAudioSessionCategoryPlayback, AVAudioSessionCategoryPlayAndRecord, nil];
  91. }
  92. - (void)ttsEedNotif:(NSNotification *)notif{
  93. NSLog(@"ttsEedNotif object:%@", notif.object);
  94. }
  95. - (void)ttsErrorNotif:(NSNotification *)notif{
  96. NSLog(@"ttsErrorNotif object:%@", notif.object);
  97. }
  98. +(void)loadedAudioModelWithName:(NSString*)modelName forLanguage:(NSString*)language{
  99. if([language isEqualToString:@"eng"]){
  100. currentOfflineEnglishModelName = modelName;
  101. }else{
  102. currentOfflineChineseModelName = modelName;
  103. }
  104. }
  105. -(void)processMultiselectResult{
  106. NSMutableArray* selected = self.selectionControllerSelectedIndexes;
  107. self.selectionControllerSelectedIndexes = nil;
  108. switch (self.ongoing_multiselection) {
  109. case SelectionControllerSelectProperty_ONLINE_AUE:
  110. {
  111. if(selected.count > 0){
  112. NSError *err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[selected objectAtIndex:0] forKey:BDS_SYNTHESIZER_PARAM_AUDIO_ENCODING];
  113. if(err){
  114. [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed set online audio encoding" value:@"" table:@"Localizable"]];
  115. }
  116. }
  117. // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:1 inSection:2]] withRowAnimation:UITableViewRowAnimationFade];
  118. break;
  119. }
  120. case SelectionControllerSelectProperty_AUDIO_SESSION_CATEGORY_OPTIONS:
  121. {
  122. int options = 0;
  123. for(NSNumber* n in selected){
  124. options|= AUDIO_SESSION_CATEGORY_OPTIONS[[n intValue]];
  125. }
  126. NSError *err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[NSNumber numberWithInt:options] forKey:BDS_SYNTHESIZER_PARAM_AUDIO_SESSION_CATEGORY_OPTIONS];
  127. if(err){
  128. [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed set synth strategy" value:@"" table:@"Localizable"]];
  129. }
  130. // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:2 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
  131. break;
  132. }
  133. case SelectionControllerSelectProperty_AUDIO_SESSION_CATEGORY:
  134. {
  135. [[BDSSpeechSynthesizer sharedInstance] setAudioSessionCategory:[self.audioSessionCategories objectAtIndex:[[selected objectAtIndex:0] integerValue]]];
  136. // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:1 inSection:0]] withRowAnimation:UITableViewRowAnimationFade];
  137. break;
  138. }
  139. case SelectionControllerSelectProperty_ONLINE_SPEAKER:
  140. {
  141. if(selected.count > 0){
  142. NSError *err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[selected objectAtIndex:0] forKey:BDS_SYNTHESIZER_PARAM_SPEAKER];
  143. if(err){
  144. [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed set online TTS speaker" value:@"" table:@"Localizable"]];
  145. }
  146. }
  147. // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:0 inSection:2]] withRowAnimation:UITableViewRowAnimationFade];
  148. break;
  149. }
  150. case SelectionControllerSelectProperty_OFFLINE_AUDIO_ENCODING:
  151. {
  152. if(selected.count > 0){
  153. NSError *err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[selected objectAtIndex:0] forKey:BDS_SYNTHESIZER_PARAM_ETTS_AUDIO_FORMAT];
  154. if(err){
  155. [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed set offline audio encoding" value:@"" table:@"Localizable"]];
  156. }
  157. // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:1 inSection:3]] withRowAnimation:UITableViewRowAnimationFade];
  158. }
  159. break;
  160. }
  161. case SelectionControllerSelectProperty_ONLINE_TTS_THRESHOLD:
  162. {
  163. if(selected.count > 0){
  164. NSError *err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[selected objectAtIndex:0] forKey:BDS_SYNTHESIZER_PARAM_ONLINE_TTS_THRESHOLD];
  165. if(err){
  166. [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed set online TTS threshold" value:@"" table:@"Localizable"]];
  167. }
  168. // [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForItem:6 inSection:1]] withRowAnimation:UITableViewRowAnimationFade];
  169. }
  170. break;
  171. }
  172. default:
  173. break;
  174. }
  175. }
  176. -(void)viewWillAppear:(BOOL)animated{
  177. [super viewWillAppear:animated];
  178. if(self.selectionControllerSelectedIndexes != nil){
  179. [self processMultiselectResult];
  180. }
  181. [self.tableView reloadData];
  182. }
  183. - (void)didReceiveMemoryWarning {
  184. [super didReceiveMemoryWarning];
  185. // Dispose of any resources that can be recreated.
  186. }
  187. -(void)displayError:(NSError*)error withTitle:(NSString*)title{
  188. NSString* errMessage = error.localizedDescription;
  189. UIAlertController *alert = [UIAlertController alertControllerWithTitle:title message:errMessage preferredStyle:UIAlertControllerStyleAlert];
  190. UIAlertAction* dismiss = [UIAlertAction actionWithTitle:[[NSBundle mainBundle] localizedStringForKey:@"OK" value:@"" table:@"Localizable"] style:UIAlertActionStyleDefault
  191. handler:^(UIAlertAction * action) {}];
  192. [alert addAction:dismiss];
  193. [self presentViewController:alert animated:YES completion:nil];
  194. }
  195. #pragma mark - Table view data source
  196. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
  197. return SettingSectionCount;
  198. }
  199. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
  200. switch (section) {
  201. case SettingSection_AudioPlayer:
  202. return [[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_ENABLE_AVSESSION_MGMT withError:nil] boolValue]?SettingRow_AudioPlayerCount:(SettingRow_AudioPlayerCount-2);
  203. case SettingSection_SynthesisGeneral:
  204. return SettingRow_SynthesisGeneralCount;
  205. case SettingSection_OnlineSynthesis:
  206. return SettingRow_OnlineSynthesisCount;
  207. default:
  208. break;
  209. }
  210. return 0;
  211. }
  212. - (nullable UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
  213. {
  214. UILabel* l = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, tableView.frame.size.width, 35)];
  215. [l setBackgroundColor:[UIColor grayColor]];
  216. switch (section) {
  217. case SettingSection_AudioPlayer:
  218. [l setText:[[NSBundle mainBundle] localizedStringForKey:@"Audio player settings" value:@"" table:@"Localizable"]];
  219. break;
  220. case SettingSection_SynthesisGeneral:
  221. [l setText:[[NSBundle mainBundle] localizedStringForKey:@"Synthesizer general settings" value:@"" table:@"Localizable"]];
  222. break;
  223. case SettingSection_OnlineSynthesis:
  224. [l setText:[[NSBundle mainBundle] localizedStringForKey:@"Online Synthesizer Settings" value:@"" table:@"Localizable"]];
  225. break;
  226. default:
  227. break;
  228. }
  229. return l;
  230. }
  231. - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
  232. {
  233. return 35;
  234. }
  235. -(NSString*)netThresholdNameFromID:(ONLINE_TTS_TRESHOLD)thresHold{
  236. switch (thresHold) {
  237. case REQ_CONNECTIVITY_ANY: return [[NSBundle mainBundle] localizedStringForKey:@"Not offline" value:@"" table:@"Localizable"];
  238. case REQ_CONNECTIVITY_3G: return [[NSBundle mainBundle] localizedStringForKey:@"have 3G or better" value:@"" table:@"Localizable"];
  239. case REQ_CONNECTIVITY_4G: return [[NSBundle mainBundle] localizedStringForKey:@"have 4G or better" value:@"" table:@"Localizable"];
  240. case REQ_CONNECTIVITY_WIFI: return [[NSBundle mainBundle] localizedStringForKey:@"have WiFi" value:@"" table:@"Localizable"];
  241. default:
  242. return [[NSBundle mainBundle] localizedStringForKey:@"Unknown" value:@"" table:@"Localizable"];
  243. }
  244. }
  245. -(UITableViewCell*)cellForGeneralSettings:(NSIndexPath* )path table:(UITableView*) tableView{
  246. switch (path.row) {
  247. case SettingRow_SynthesisGeneral_SynthVolume:
  248. {
  249. // Volume
  250. SliderTableViewCell* cell = (SliderTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"SLIDER_CELL" forIndexPath:path];
  251. cell.PROPERTY_ID = EDIT_PROPERTY_ID_VOLUME;
  252. int currentValue = [[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_VOLUME withError:nil] intValue];
  253. [cell.valueSlider setMaximumValue:15.0];
  254. [cell.valueSlider setMinimumValue:0.0];
  255. [cell.valueSlider setValue:(float)currentValue];
  256. [cell.currentValueLabel setText:[NSString stringWithFormat:@"%d", currentValue]];
  257. cell.isContinuous = NO;
  258. cell.delegate = self;
  259. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Speech volume" value:@"" table:@"Localizable"]];
  260. return cell;
  261. }
  262. case SettingRow_SynthesisGeneral_SynthSpeed:
  263. {
  264. // Speed
  265. SliderTableViewCell* cell = (SliderTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"SLIDER_CELL" forIndexPath:path];
  266. cell.PROPERTY_ID = EDIT_PROPERTY_ID_SPEED;
  267. int currentValue = [[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_SPEED withError:nil] intValue];
  268. [cell.valueSlider setMaximumValue:9.0];
  269. [cell.valueSlider setMinimumValue:0.0];
  270. [cell.valueSlider setValue:(float)currentValue];
  271. [cell.currentValueLabel setText:[NSString stringWithFormat:@"%d", currentValue]];
  272. cell.isContinuous = NO;
  273. cell.delegate = self;
  274. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Speech speed" value:@"" table:@"Localizable"]];
  275. return cell;
  276. }
  277. case SettingRow_SynthesisGeneral_SynthPitch:
  278. {
  279. // Pitch
  280. SliderTableViewCell* cell = (SliderTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"SLIDER_CELL" forIndexPath:path];
  281. cell.PROPERTY_ID = EDIT_PROPERTY_ID_PITCH;
  282. int currentValue = [[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_PITCH withError:nil] intValue];
  283. [cell.valueSlider setMaximumValue:9.0];
  284. [cell.valueSlider setMinimumValue:0.0];
  285. [cell.valueSlider setValue:(float)currentValue];
  286. [cell.currentValueLabel setText:[NSString stringWithFormat:@"%d", currentValue]];
  287. cell.isContinuous = NO;
  288. cell.delegate = self;
  289. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Speech pitch" value:@"" table:@"Localizable"]];
  290. return cell;
  291. }
  292. case SettingRow_SynthesisGeneral_EnableSpeak:
  293. {
  294. // Enable speak
  295. SwitchTableViewCell* cell = (SwitchTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"SWITCH_CELL" forIndexPath:path];
  296. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Enable speak" value:@"" table:@"Localizable"]];
  297. // [cell.stateSwitch setOn:[TTSViewController isSpeakEnabled]];
  298. cell.delegate = self;
  299. cell.PROPERTY_ID = EDIT_PROPERTY_ID_ENABLE_SPEAK;
  300. return cell;
  301. }
  302. case SettingRow_SynthesisGeneral_ReadTextFromFile:
  303. {
  304. // Read text from tts_text.txt
  305. SwitchTableViewCell* cell = (SwitchTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"SWITCH_CELL" forIndexPath:path];
  306. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Read text from tts_text.txt" value:@"" table:@"Localizable"]];
  307. cell.PROPERTY_ID = EDIT_PROPERTY_ID_ENABLE_FILE_SYNTH;
  308. // [cell.stateSwitch setOn:[TTSViewController isFileSynthesisEnabled]];
  309. cell.delegate = self;
  310. return cell;
  311. }
  312. case SettingRow_SynthesisGeneral_OnlineThreshold:
  313. {
  314. // threshold
  315. NavigationTableViewCell* cell = (NavigationTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"NAVIGATE_CELL" forIndexPath:path];
  316. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Prefer Online TTS when" value:@"" table:@"Localizable"]];
  317. [cell.currentValueLabel setText:[self netThresholdNameFromID:(ONLINE_TTS_TRESHOLD)[[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_ONLINE_TTS_THRESHOLD withError:nil] intValue]]];
  318. return cell;
  319. }
  320. default:
  321. break;
  322. }
  323. return nil;
  324. }
  325. -(NSString*)onlineSpeakerDescriptionFromID:(NSInteger)speakerID{
  326. switch (speakerID) {
  327. case 0: return [[NSBundle mainBundle] localizedStringForKey:@"Female, f7" value:@"" table:@"Localizable"];
  328. case 1: return [[NSBundle mainBundle] localizedStringForKey:@"Male, macs" value:@"" table:@"Localizable"];
  329. case 2: return [[NSBundle mainBundle] localizedStringForKey:@"Male, m15" value:@"" table:@"Localizable"];
  330. case 3: return [[NSBundle mainBundle] localizedStringForKey:@"Male, yyjw" value:@"" table:@"Localizable"];
  331. case 4: return [[NSBundle mainBundle] localizedStringForKey:@"Duyaya" value:@"" table:@"Localizable"];
  332. default:
  333. return [[NSBundle mainBundle] localizedStringForKey:@"Unknown" value:@"" table:@"Localizable"];
  334. }
  335. }
  336. -(NSString*)OnlineAudioEncodingDescFromID:(NSInteger)AUEID{
  337. switch (AUEID) {
  338. case BDS_SYNTHESIZER_AUDIO_ENCODE_BV_16K: return @"BroadVoice 16kbps";
  339. case BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_6K6: return @"AMR 6.6kbps";
  340. case BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_8K85: return @"AMR 8.85kbps";
  341. case BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_12K65: return @"AMR 12.65kbps";
  342. case BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_14K25: return @"AMR 14.25kbps";
  343. case BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_15K85: return @"AMR 15.85kbps";
  344. case BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_18K25: return @"AMR 18.25kbps";
  345. case BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_19K85: return @"AMR 19.85kbps";
  346. case BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_23K05: return @"AMR 23.05kbps";
  347. case BDS_SYNTHESIZER_AUDIO_ENCODE_AMR_23K85: return @"AMR 23.85kbps";
  348. case BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_8K: return @"Opus 8kbps";
  349. case BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_16K:return @"Opus 16kbps";
  350. case BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_18K: return @"Opus 18kbps";
  351. case BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_20K: return @"Opus 20kbps";
  352. case BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_24K: return @"Opus 24kbps";
  353. case BDS_SYNTHESIZER_AUDIO_ENCODE_OPUS_32K: return @"Opus 32kbps";
  354. case BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_8K: return @"MP3 8kbps";
  355. case BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_11K: return @"MP3 11kbps";
  356. case BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_16K: return @"MP3 16kbps";
  357. case BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_24K: return @"MP3 24kbps";
  358. case BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_32K: return @"MP3 32kbps";
  359. default:
  360. return [[NSBundle mainBundle] localizedStringForKey:@"Unknown" value:@"" table:@"Localizable"];
  361. }
  362. }
  363. - (UITableViewCell*)cellForOnlineTTSSettings:(UITableView *)tableView IndexPath:(NSIndexPath *)indexPath{
  364. switch (indexPath.row) {
  365. case SettingRow_OnlineSynthesis_Speaker:
  366. {
  367. // speaker
  368. NavigationTableViewCell* cell = (NavigationTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"NAVIGATE_CELL" forIndexPath:indexPath];
  369. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Speaker" value:@"" table:@"Localizable"]];
  370. [cell.currentValueLabel setText:[self onlineSpeakerDescriptionFromID:[[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_SPEAKER withError:nil] integerValue]]];
  371. return cell;
  372. }
  373. case SettingRow_OnlineSynthesis_AudioEncoding:
  374. {
  375. // audio encoding
  376. NavigationTableViewCell* cell = (NavigationTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"NAVIGATE_CELL" forIndexPath:indexPath];
  377. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Audio encoding" value:@"" table:@"Localizable"]];
  378. [cell.currentValueLabel setText:[self OnlineAudioEncodingDescFromID:[[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_AUDIO_ENCODING withError:nil] integerValue]]];
  379. return cell;
  380. }
  381. case SettingRow_OnlineXml:
  382. {
  383. SwitchTableViewCell* cell = (SwitchTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"SWITCH_CELL" forIndexPath:indexPath];
  384. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Enable xml" value:@"" table:@"Localizable"]];
  385. cell.PROPERTY_ID = EDIT_PROPERTY_ID_ONLINE_TTS_XML;
  386. [cell.stateSwitch setOn:([[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_ONLINE_OPEN_XML withError:nil] integerValue] == 1)];
  387. cell.delegate = self;
  388. return cell;
  389. }
  390. default:
  391. break;
  392. }
  393. return nil;
  394. }
  395. -(NSString*)offlineSpeakerDescriptionFromID:(NSInteger)speakerID{
  396. switch (speakerID) {
  397. case 0: return [[NSBundle mainBundle] localizedStringForKey:@"Female" value:@"" table:@"Localizable"];
  398. case 1: return [[NSBundle mainBundle] localizedStringForKey:@"Male" value:@"" table:@"Localizable"];
  399. default:
  400. return [[NSBundle mainBundle] localizedStringForKey:@"Unknown" value:@"" table:@"Localizable"];
  401. }
  402. }
  403. -(NSString*)OfflineAudioEncodingDescFromID:(NSInteger)AUEID{
  404. switch (AUEID) {
  405. case ETTS_AUDIO_TYPE_PCM_16K: return @"16 bit PCM 16 khz";
  406. case ETTS_AUDIO_TYPE_PCM_8K: return @"16 bit PCM 8 khz";
  407. default:
  408. return @"Unknown";
  409. }
  410. }
  411. - (UITableViewCell*)cellForAudioSettings:(UITableView *)tableView IndexPath:(NSIndexPath *)indexPath{
  412. switch (indexPath.row) {
  413. case SettingRow_AudioPlayer_AudioVolume:
  414. {
  415. // Volume
  416. SliderTableViewCell* cell = (SliderTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"SLIDER_CELL" forIndexPath:indexPath];
  417. cell.PROPERTY_ID = EDIT_PROPERTY_ID_PLAYER_VOLUME;
  418. [cell.valueSlider setMaximumValue:1.0];
  419. [cell.valueSlider setMinimumValue:0.0];
  420. [cell.valueSlider setValue:SDK_PLAYER_VOLUME];
  421. [cell.currentValueLabel setText:[NSString stringWithFormat:@"%.2f", SDK_PLAYER_VOLUME]];
  422. cell.isContinuous = YES;
  423. cell.delegate = self;
  424. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Volume" value:@"" table:@"Localizable"]];
  425. return cell;
  426. }
  427. case SettingRow_AudioPlayer_Enable_AVAudioSessionManagement:{
  428. // Enable management
  429. SwitchTableViewCell* cell = (SwitchTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"SWITCH_CELL" forIndexPath:indexPath];
  430. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Audio session management" value:@"" table:@"Localizable"]];
  431. [cell.stateSwitch setOn:[[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_ENABLE_AVSESSION_MGMT withError:nil] boolValue]];
  432. cell.delegate = self;
  433. cell.PROPERTY_ID = EDIT_PROPERTY_ID_ENABLE_AUDIO_SESSION_MANAGEMENT;
  434. return cell;
  435. }
  436. case SettingRow_AudioPlayer_AVAudiosessionCategory:
  437. {
  438. // category
  439. NavigationTableViewCell* cell = (NavigationTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"NAVIGATE_CELL" forIndexPath:indexPath];
  440. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Category" value:@"" table:@"Localizable"]];
  441. [cell.currentValueLabel setText:[BDSSpeechSynthesizer sharedInstance].audioSessionCategory];
  442. return cell;
  443. }
  444. case SettingRow_AudioPlayer_AVAudioSessionCategoryOptions:
  445. {
  446. // category options
  447. NavigationTableViewCell* cell = (NavigationTableViewCell*)[tableView dequeueReusableCellWithIdentifier:@"NAVIGATE_CELL" forIndexPath:indexPath];
  448. [cell.nameLabel setText:[[NSBundle mainBundle] localizedStringForKey:@"Audio session category opts" value:@"" table:@"Localizable"]];
  449. [cell.currentValueLabel setText:@""];
  450. return cell;
  451. }
  452. default:
  453. break;
  454. }
  455. return nil;
  456. }
  457. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  458. switch(indexPath.section){
  459. case SettingSection_AudioPlayer:
  460. return [self cellForAudioSettings:tableView IndexPath:indexPath];
  461. case SettingSection_SynthesisGeneral:
  462. return [self cellForGeneralSettings:indexPath table:tableView];
  463. case SettingSection_OnlineSynthesis:
  464. return [self cellForOnlineTTSSettings:tableView IndexPath:indexPath];
  465. }
  466. return [tableView dequeueReusableCellWithIdentifier:@"NAVIGATE_CELL" forIndexPath:indexPath];
  467. }
  468. - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSIndexPath *)indexPath
  469. {
  470. switch (indexPath.section) {
  471. case SettingSection_AudioPlayer:
  472. {
  473. switch (indexPath.row) {
  474. case SettingRow_AudioPlayer_Enable_AVAudioSessionManagement:
  475. return NO;
  476. case SettingRow_AudioPlayer_AVAudiosessionCategory:
  477. case SettingRow_AudioPlayer_AVAudioSessionCategoryOptions:
  478. return YES;
  479. default:
  480. break;
  481. }
  482. }
  483. case SettingSection_SynthesisGeneral:
  484. {
  485. switch (indexPath.row) {
  486. case SettingRow_SynthesisGeneral_SynthVolume:
  487. case SettingRow_SynthesisGeneral_SynthSpeed:
  488. case SettingRow_SynthesisGeneral_SynthPitch:
  489. case SettingRow_SynthesisGeneral_EnableSpeak:
  490. case SettingRow_SynthesisGeneral_ReadTextFromFile:
  491. return NO;
  492. case SettingRow_SynthesisGeneral_OnlineThreshold:
  493. return YES; // select strategy
  494. default:
  495. return NO;
  496. }
  497. }
  498. case SettingSection_OnlineSynthesis:
  499. switch (indexPath.row) {
  500. case SettingRow_OnlineSynthesis_Speaker:
  501. case SettingRow_OnlineSynthesis_AudioEncoding:
  502. return YES;
  503. default:
  504. return NO;
  505. }
  506. default:
  507. return NO;
  508. }
  509. return NO;
  510. }
  511. - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  512. {
  513. [tableView deselectRowAtIndexPath:indexPath animated:YES];
  514. // switch (indexPath.section) {
  515. // case SettingSection_AudioPlayer:
  516. // {
  517. // switch (indexPath.row) {
  518. // case SettingRow_AudioPlayer_AVAudiosessionCategory:{
  519. // // select category
  520. // NSString * storyboardName = @"TTSMain";
  521. // UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
  522. // SelectionTableViewController * vc = (SelectionTableViewController*)[storyboard instantiateViewControllerWithIdentifier:@"SINGLE_OR_MULTISELECT_VIEW"];
  523. // vc.isMultiSelect = NO;
  524. // vc.allowNoneSelected = NO;
  525. // NSString* currCategory = [BDSSpeechSynthesizer sharedInstance].audioSessionCategory;
  526. // int selectedCategory = 0;
  527. // for(NSString* string in self.audioSessionCategories){
  528. // if([currCategory isEqualToString:string]){
  529. // break;
  530. // }
  531. // selectedCategory++;
  532. // }
  533. // if(selectedCategory >= self.audioSessionCategories.count)selectedCategory = 0;
  534. //
  535. // NSMutableArray* selectedItems = [[NSMutableArray alloc] initWithObjects:[NSNumber numberWithInt:selectedCategory], nil];
  536. // vc.title = [[NSBundle mainBundle] localizedStringForKey:@"Synthesis strategy" value:@"" table:@"Localizable"];
  537. // vc.selectableItemNames = self.audioSessionCategories;
  538. // vc.selectedItems = selectedItems;
  539. // self.ongoing_multiselection = SelectionControllerSelectProperty_AUDIO_SESSION_CATEGORY;
  540. // self.selectionControllerSelectedIndexes = selectedItems;
  541. // [self.navigationController pushViewController:vc animated:YES];
  542. // break;
  543. // }
  544. // case SettingRow_AudioPlayer_AVAudioSessionCategoryOptions:{
  545. // // select options
  546. // NSString * storyboardName = @"TTSMain";
  547. // UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
  548. //// SelectionTableViewController * vc = (SelectionTableViewController*)[storyboard instantiateViewControllerWithIdentifier:@"SINGLE_OR_MULTISELECT_VIEW"];
  549. //// vc.isMultiSelect = YES;
  550. // vc.allowNoneSelected = YES;
  551. //
  552. // int currFlags = [[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_AUDIO_SESSION_CATEGORY_OPTIONS withError:nil] intValue];
  553. //
  554. // NSMutableArray* selectedItems = [[NSMutableArray alloc] init];
  555. // NSMutableArray* options = [[NSMutableArray alloc] init];
  556. // for(int i = 0;i<AVAILABLE_AV_CATEGORY_OPTION_COUNT;i++){
  557. // if((currFlags&AUDIO_SESSION_CATEGORY_OPTIONS[i]) == AUDIO_SESSION_CATEGORY_OPTIONS[i])
  558. // {
  559. // [selectedItems addObject:[NSNumber numberWithInt:i]];
  560. // }
  561. // [options addObject:AUDIO_SESSION_CATEGORY_OPT_NAMES[i]];
  562. // }
  563. // vc.title = [[NSBundle mainBundle] localizedStringForKey:@"AV session category options" value:@"" table:@"Localizable"];
  564. // vc.selectableItemNames = options;
  565. // vc.selectedItems = selectedItems;
  566. // self.ongoing_multiselection = SelectionControllerSelectProperty_AUDIO_SESSION_CATEGORY_OPTIONS;
  567. // self.selectionControllerSelectedIndexes = selectedItems;
  568. // [self.navigationController pushViewController:vc animated:YES];
  569. // break;
  570. // }
  571. // default:
  572. // break;
  573. // }
  574. // break;
  575. // }
  576. // case SettingSection_SynthesisGeneral:
  577. // {
  578. // switch (indexPath.row) {
  579. // case SettingRow_SynthesisGeneral_OnlineThreshold:{
  580. // NSString * storyboardName = @"TTSMain";
  581. // UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
  582. // SelectionTableViewController * vc = (SelectionTableViewController*)[storyboard instantiateViewControllerWithIdentifier:@"SINGLE_OR_MULTISELECT_VIEW"];
  583. // vc.isMultiSelect = NO;
  584. // vc.allowNoneSelected = NO;
  585. // ONLINE_TTS_TRESHOLD curr = (ONLINE_TTS_TRESHOLD)[[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_ONLINE_TTS_THRESHOLD withError:nil] intValue];
  586. // NSMutableArray* selectedItems = [[NSMutableArray alloc] initWithObjects:[NSNumber numberWithInt:curr], nil];
  587. // NSMutableArray* options = [[NSMutableArray alloc] init];
  588. // for(ONLINE_TTS_TRESHOLD m = REQ_CONNECTIVITY_ANY;m <= REQ_CONNECTIVITY_WIFI;m++){
  589. // [options addObject:[self netThresholdNameFromID:m]];
  590. // }
  591. // vc.title = [[NSBundle mainBundle] localizedStringForKey:@"Online TTS preferred when" value:@"" table:@"Localizable"];
  592. // vc.selectableItemNames = options;
  593. // vc.selectedItems = selectedItems;
  594. // self.ongoing_multiselection = SelectionControllerSelectProperty_ONLINE_TTS_THRESHOLD;
  595. // self.selectionControllerSelectedIndexes = selectedItems;
  596. // [self.navigationController pushViewController:vc animated:YES];
  597. // break;
  598. // }
  599. // default:
  600. // break;
  601. // }
  602. // break;
  603. // }
  604. // case SettingSection_OnlineSynthesis:
  605. // switch (indexPath.row) {
  606. // case SettingRow_OnlineSynthesis_Speaker:{
  607. // // online speaker
  608. // NSString * storyboardName = @"TTSMain";
  609. // UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
  610. // SelectionTableViewController * vc = (SelectionTableViewController*)[storyboard instantiateViewControllerWithIdentifier:@"SINGLE_OR_MULTISELECT_VIEW"];
  611. // vc.isMultiSelect = NO;
  612. // vc.allowNoneSelected = NO;
  613. // NSInteger currentSpeaker = [[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_SPEAKER withError:nil] integerValue];
  614. // NSMutableArray* availableItems = [[NSMutableArray alloc] init];
  615. // for (NSInteger i = 0; i < KNOWN_ONLINE_SPEAKER_COUNT; i++) {
  616. // [availableItems addObject:[self onlineSpeakerDescriptionFromID:i]];
  617. // }
  618. // NSMutableArray* selectedItems = [[NSMutableArray alloc] initWithObjects:[NSNumber numberWithInteger:currentSpeaker], nil];
  619. // vc.title = [[NSBundle mainBundle] localizedStringForKey:@"Online speaker" value:@"" table:@"Localizable"];
  620. // vc.selectableItemNames = availableItems;
  621. // vc.selectedItems = selectedItems;
  622. // self.ongoing_multiselection = SelectionControllerSelectProperty_ONLINE_SPEAKER;
  623. // self.selectionControllerSelectedIndexes = selectedItems;
  624. // [self.navigationController pushViewController:vc animated:YES];
  625. // break;
  626. // }
  627. // case SettingRow_OnlineSynthesis_AudioEncoding:{
  628. // // online audio format
  629. // NSString * storyboardName = @"TTSMain";
  630. // UIStoryboard *storyboard = [UIStoryboard storyboardWithName:storyboardName bundle: nil];
  631. // SelectionTableViewController * vc = (SelectionTableViewController*)[storyboard instantiateViewControllerWithIdentifier:@"SINGLE_OR_MULTISELECT_VIEW"];
  632. // vc.isMultiSelect = NO;
  633. // vc.allowNoneSelected = NO;
  634. // NSInteger currentEncoding = [[[BDSSpeechSynthesizer sharedInstance] getSynthParamforKey:BDS_SYNTHESIZER_PARAM_AUDIO_ENCODING withError:nil] integerValue];
  635. // NSMutableArray* availableItems = [[NSMutableArray alloc] init];
  636. // for (NSInteger i = 0; i <= BDS_SYNTHESIZER_AUDIO_ENCODE_MP3_32K; i++) {
  637. // [availableItems addObject:[self OnlineAudioEncodingDescFromID:i]];
  638. // }
  639. // NSMutableArray* selectedItems = [[NSMutableArray alloc] initWithObjects:[NSNumber numberWithInteger:currentEncoding], nil];
  640. // vc.title = [[NSBundle mainBundle] localizedStringForKey:@"Online audio encoding" value:@"" table:@"Localizable"];
  641. // vc.selectableItemNames = availableItems;
  642. // vc.selectedItems = selectedItems;
  643. // self.ongoing_multiselection = SelectionControllerSelectProperty_ONLINE_AUE;
  644. // self.selectionControllerSelectedIndexes = selectedItems;
  645. // [self.navigationController pushViewController:vc animated:YES];
  646. // break;
  647. // }
  648. // default:
  649. // break;
  650. // }
  651. // break;
  652. // default:
  653. // break;
  654. // }
  655. }
  656. #pragma mark - SwitchTableViewCellDelegate
  657. -(void)switchStateChanged:(BOOL)newState forPropertyID:(NSString*)propertyID{
  658. // if([EDIT_PROPERTY_ID_ENABLE_FILE_SYNTH isEqualToString:propertyID]){
  659. // [TTSViewController setFileSynthesisEnabled:newState];
  660. // }
  661. // else if([EDIT_PROPERTY_ID_ENABLE_SPEAK isEqualToString:propertyID]){
  662. // [TTSViewController setSpeakEnabled:newState];
  663. // }
  664. // else if([EDIT_PROPERTY_ID_ENABLE_AUDIO_SESSION_MANAGEMENT isEqualToString:propertyID]){
  665. // NSError* err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[NSNumber numberWithBool:newState] forKey:BDS_SYNTHESIZER_PARAM_ENABLE_AVSESSION_MGMT];
  666. // if(err){
  667. // [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed to change audio session management status" value:@"" table:@"Localizable"]];
  668. // return;
  669. // }
  670. // [self.tableView beginUpdates];
  671. // [self.tableView reloadSections:[[NSIndexSet alloc] initWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
  672. // [self.tableView endUpdates];
  673. // }
  674. // else if([EDIT_PROPERTY_ID_ONLINE_TTS_XML isEqualToString:propertyID]){
  675. // NSError* err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:(newState?[NSNumber numberWithInt:1]:[NSNumber numberWithInt:0]) forKey:BDS_SYNTHESIZER_PARAM_ONLINE_OPEN_XML];
  676. // if(err){
  677. // [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed set online xml" value:@"" table:@"Localizable"]];
  678. // }
  679. // }
  680. // else if([EDIT_PROPERTY_ID_OFFLINE_TTS_XML isEqualToString:propertyID]){
  681. // NSError* err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:(newState?[NSNumber numberWithInt:1]:[NSNumber numberWithInt:0]) forKey:BDS_SYNTHESIZER_PARAM_ETTS_OPEN_XML];
  682. // if(err){
  683. // [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed set online xml" value:@"" table:@"Localizable"]];
  684. // }
  685. // }
  686. }
  687. #pragma mark - SliderTableViewCellDelegate
  688. -(void)sliderValueChanged:(float)newValue forProperty:(NSString*)propertyID fromSlider:(SliderTableViewCell*)src{
  689. if([EDIT_PROPERTY_ID_VOLUME isEqualToString:propertyID]){
  690. int value = (int)newValue;
  691. NSError* err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[NSNumber numberWithInteger:value] forKey:BDS_SYNTHESIZER_PARAM_VOLUME];
  692. if(err){
  693. [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed set synth volume" value:@"" table:@"Localizable"]];
  694. }
  695. }
  696. else if([EDIT_PROPERTY_ID_SPEED isEqualToString:propertyID]){
  697. int value = (int)newValue;
  698. NSError* err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[NSNumber numberWithInteger:value] forKey:BDS_SYNTHESIZER_PARAM_SPEED];
  699. if(err){
  700. [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed set synth speed" value:@"" table:@"Localizable"]];
  701. }
  702. }
  703. else if([EDIT_PROPERTY_ID_PITCH isEqualToString:propertyID]){
  704. int value = (int)newValue;
  705. NSError* err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[NSNumber numberWithInteger:value] forKey:BDS_SYNTHESIZER_PARAM_PITCH];
  706. if(err){
  707. [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed set synth pitch" value:@"" table:@"Localizable"]];
  708. }
  709. }
  710. else if([EDIT_PROPERTY_ID_PLAYER_VOLUME isEqualToString:propertyID]){
  711. SDK_PLAYER_VOLUME = newValue;
  712. [[BDSSpeechSynthesizer sharedInstance] setPlayerVolume:newValue];
  713. }
  714. }
  715. #pragma mark - InputTableViewCellDelegate
  716. -(void)InputCellChangedValue:(NSString*)newValue forProperty:(NSString*)propertyID
  717. {
  718. if([EDIT_PROPERTY_ID_TTS_ONLINE_TIMEOUT isEqualToString:propertyID]){
  719. NSError* err = [[BDSSpeechSynthesizer sharedInstance] setSynthParam:[NSNumber numberWithFloat:[newValue floatValue]] forKey:BDS_SYNTHESIZER_PARAM_ONLINE_REQUEST_TIMEOUT];
  720. if(err){
  721. [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Failed set online tts timeout" value:@"" table:@"Localizable"]];
  722. }
  723. }
  724. else if([EDIT_PROPERTY_ID_OFFLINE_TTS_APPID isEqualToString:propertyID]){
  725. // // switching app id requires reloading whole engine
  726. // NSString* offlineEngineSpeechData = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:offlineSpeakerChineseSpeechDats[setOfflineSpeaker]] ofType:@"dat"];
  727. // NSString* offlineEngineTextData = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:offlineSpeakerChineseTextDats[setOfflineSpeaker]] ofType:@"dat"];
  728. // NSString* offlineEngineEnglishSpeechData = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:offlineSpeakerEnglishSpeechDats[setOfflineSpeaker]] ofType:@"dat"];
  729. // NSString* offlineEngineEnglishTextData = [[NSBundle mainBundle] pathForResource:[NSString stringWithUTF8String:offlineSpeakerEnglishTextDats[setOfflineSpeaker]] ofType:@"dat"];
  730. // NSString* offlineEngineLicenseFile = [[NSBundle mainBundle] pathForResource:@"offline_engine_tmp_license" ofType:@"dat"];
  731. //
  732. // NSError* err = [[BDSSpeechSynthesizer sharedInstance] loadOfflineEngine:offlineEngineTextData speechDataPath:offlineEngineSpeechData licenseFilePath:offlineEngineLicenseFile withAppCode:newValue];
  733. // if(err){
  734. // [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Offline TTS init failed" value:@"" table:@"Localizable"]];
  735. // setOfflineSpeaker = OfflineSpeaker_None;
  736. // return;
  737. // }
  738. // err = [[BDSSpeechSynthesizer sharedInstance] loadEnglishDataForOfflineEngine:offlineEngineEnglishTextData speechData:offlineEngineEnglishSpeechData];
  739. // if(err){
  740. // [self displayError:err withTitle:[[NSBundle mainBundle] localizedStringForKey:@"Offline TTS load English support failed" value:@"" table:@"Localizable"]];
  741. // return;
  742. // }
  743. // setOfflineAppID = newValue;
  744. }
  745. [self.tableView reloadData];
  746. }
  747. @end