0

こんにちは、私は iOS の初心者で、特定のタスクがあります。まず、AVAudioRecorder でサウンドを録音し、問題なく録音および再生できますが、レコードのバイトでデータを取得する必要があります。ここに私の機能があります。

@interface recordViewController : UIViewController <AVAudioRecorderDelegate, AVAudioPlayerDelegate>
{
    AVAudioRecorder *audioRecorder;
    AVAudioPlayer *audioPlayer;
    UIButton *playButton;
    UIButton *recordButton;
    UIButton *stopButton;
}

記録:

 -(void) recordAudio {
     if (!audioRecorder.recording)
     {
         playButton.enabled = NO;
         stopButton.enabled = YES;
         [audioRecorder record];
     }
}

遊ぶ:

-(void) playAudio {
    if (!audioRecorder.recording)
    {
        stopButton.enabled = YES;
        recordButton.enabled = NO;

        NSError *error;

        audioPlayer = [[AVAudioPlayer alloc] 
                       initWithContentsOfURL:audioRecorder.url
                       error:&error];

        audioPlayer.delegate = self;

        if (error)
            NSLog(@"Error: %@", [error localizedDescription]);
        else
            [audioPlayer play];
    } 
}

レコードのバイト単位でデータを取得するにはどうすればよいですか? iOS Developer API で検索しましたが、何も見つかりませんでした。

4

1 に答える 1

0

私はこの解決策を試していません。しかし、これは役立つ可能性があります。それを試してみてください。

音声を録音するには:

itsVoiceRecordedURL = [NSURL fileURLWithPath:[NSString stringWithFormat:<Path of the recorded file to be stored>]];
    NSMutableDictionary* recordSetting = [[NSMutableDictionary alloc] init];
    [recordSetting setValue :[NSNumber numberWithInt:kAudioFormatAppleIMA4] forKey:AVFormatIDKey];
    [recordSetting setValue:[NSNumber numberWithFloat:44100.0] forKey:AVSampleRateKey]; 
    [recordSetting setValue:[NSNumber numberWithInt: 2] forKey:AVNumberOfChannelsKey];

    itsAudioRecorder = [[ AVAudioRecorder alloc] initWithURL:itsVoiceRecordedURL settings:recordSetting error:&error];
    [recordSetting release];
    [itsAudioRecorder setDelegate:self];
    //We call this to start the recording process and initialize 
    //the subsstems so that when we actually say "record" it starts right away.
    [itsAudioRecorder prepareToRecord];
    //Start the actual Recording
    [itsAudioRecorder record];

録音したオーディオ ファイルをバイト配列に変換するには

NSData *data = [NSData dataWithContentsOfFile:AudioFilePath];
NSUInteger len = [data length];
Byte *byteData = (Byte*)malloc(len);
于 2012-05-29T04:31:06.097 に答える