SpeakHere sample cannot reproduce sound that is downloaded from the Internet

I would like to play a sound file downloaded from the Internet, so I tried to start with the SpeakHere iPhone SDK example. I recorded the sound, then saved and uploaded to the Internet, I could download this file and play sound instruments without any problems. But when I tried to reproduce this URL from SpeakHere, I get an error Program received signal: "EXC_BAD_ACCESS".

After tracing, I found that in -[AudioPlayer calculateSizesFor:]it I set bufferByteSizeto a huge number 806128768, which caused the buffer allocation to fail.

And this is because in

AudioFileGetProperty(audioFileID, kAudioFilePropertyPacketSizeUpperBound, &propertySize, &maxPacketSize);

Returns maxPacketSize806128768.

I am wondering how to do the job AudioFileGetProperty.

My sound file is here , you can right-click and download from here .

I use this method to set the url in a method -[AudioViewController playOrStop]:

// AudioPlayer *thePlayer = [[AudioPlayer alloc] initWithURL: self.soundFileURL];
AudioPlayer *thePlayer = [[AudioPlayer alloc] initWithURL:
    [NSURL URLWithString: @"http://chineseresume.com/localbiz/uploads/myfilename_7_Recording.caf"]];

Any suggestion is welcome.

+3
source share
3 answers

Yes, you need to use Audio File Stream Services to play directly from the Internet.

I found the example "AudioFileStreamExample" useful, which should be set to

/Developer/Examples/CoreAudio/Services/AudioFileStreamExample/

, "" MP3", iPhone. , , , .

+4

, , AudioFile ( ), , AudioFileStream, API , AudioFileStreamOpen, AudioFileStreamParseBytes ..

+3

. , . .

, . - , , .

.

-(CFURLRef)saveURL:(NSString *)urlString {
    NSURL *url = (NSURL*)[[NSURL alloc] initWithString:urlString];
    NSData *data = [[NSData alloc] initWithContentsOfURL:url];
    NSArray *filePaths =    NSSearchPathForDirectoriesInDomains (                        NSDocumentDirectory,                                                        NSUserDomainMask,                                                   YES                                                    ); 

    NSString *recordingDirectory = [filePaths objectAtIndex: 0];

    CFStringRef fileString = (CFStringRef) [NSString stringWithFormat: @"%@/BufferFile.caf", recordingDirectory];
    NSLog(@"fileString = %@" , fileString);
    // create the file URL that identifies the file that the recording audio queue object records into
    CFURLRef fileURL =  CFURLCreateWithFileSystemPath (                                                NULL,   fileString,                                             kCFURLPOSIXPathStyle,                                             false);
    SInt32 err = 0;

    CFURLWriteDataAndPropertiesToResource (
  fileURL, (CFDataRef)data, nil, &err);
    return fileURL;
}
+1
source

Source: https://habr.com/ru/post/1699635/


All Articles