3

I want to save audio file generated by TTS SDK. I am not sure what is correct way to do it with NSURL path.

This is the code, but result says NO. If I don't try saving audio file, MyAcaTTS works fine.

NSString *FileNamePath = [[NSBundle mainBundle] pathForResource:@"testAudio" ofType:@"aiff"]; NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *appSettingsPath = [documentsDirectory stringByAppendingPathComponent:FileNamePath]; NSURL *url=[[NSURL alloc]initWithString:appSettingsPath]; BOOL result = [MyAcaTTS_ startSpeakingString:@"testing" toURL:url]; 

Document of Acapela iPhone SDK.

6.2.3.startSpeakingString:toURL: Synopsis

  • (BOOL)startSpeakingString:(NSString *)string toURL:url;

Description

Begins synthesizing string into a sound (AIFF) file. When synthesis of string finishes normally or is stopped, the message speechSynthesizer:didFinishSpeaking: is sent to the delegate. Parameters string Text to synthesize. When nil or empty, no synthesis occurs. url Filesystem location of the output sound file. Return value YES when synthesis starts successfully, NO otherwise.

http://www.ecometrixem.com/cms-assets/documents/44729-919017.acapela-for-iphone.pdf

1 Answer 1

2

There are two things for you to consider in your code:

  1. The line NSString *FileNamePath = [[NSBundle mainBundle] pathForResource:@"testAudio" ofType:@"aiff"]; is not required since it returns full path of the file while you need only the last part of it: "testAudio.aiff"

  2. You construct URL object with constructor accepting strings with valid protocol prefix, like "http://" or "ftp://" while your need another constructor named initFileURLWithPath: instead.

So with all the above your code may look like this:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *documentsDirectory = [paths objectAtIndex:0]; NSString *appSettingsPath = [documentsDirectory stringByAppendingPathComponent:@"testAudio.aiff"]; NSURL *url=[[NSURL alloc]initFileURLWithPath:appSettingsPath]; BOOL result = [MyAcaTTS_ startSpeakingString:@"testing" toURL:url]; 
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you! It finally created a file, but it still doesn't make any sound, it's just a empty aiff file. BOOL result gives a error. Maybe I need to use another file type...
Actually, it was because MyAcaTTS was speaking another text just before the codes, it works fine now, thank you very much!
If we have 2 statements calling [self.MyAcaTTS startSpeakingString:text]; with the 2nd statement writing to a file, it does not work, otherwise, the file gets created with audio contents. NSURL construction is not the issue here it seems. [self.MyAcaTTS startSpeakingString:phrase toURL:[NSURL fileURLWithPath:filePath]];

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.