저는 SpeakHere 샘플 코드에서 오디오 레코더 및 AQRecorder를 사용하고 있습니다. 녹음 기간을 표시하기 위해 UI에 슬라이더를 추가하고 싶습니다. 녹음 시작시 초기화 된 간단한 타이머를 사용하여이 작업을 수행했습니다. 그러나 때로는 녹음이 1 초 뒤쳐져 있습니다. 예를 들어 슬라이더에 10 초가 표시되지만 저장시 오디오의 실제 지속 시간은 9 초입니다.녹음하는 동안 녹음 된 오디오의 정확한 길이를 얻는 방법?
타이머를 사용하는 대신 슬라이더를 업데이트하기 위해 녹화하는 동안 정확한 길이를 얻을 수있는 방법이 있습니까?
제가 또한NSTimeInterval AQRecorder::GetTotalDuration()
{
UInt64 nPackets;
UInt32 propsize = sizeof(nPackets);
XThrowIfError (AudioFileGetProperty(mRecordFile, kAudioFilePropertyAudioDataPacketCount, &propsize, &nPackets), "kAudioFilePropertyAudioDataPacketCount");
Float64 fileDuration = (nPackets * mRecordFormat.mFramesPerPacket)/mRecordFormat.mSampleRate;
return fileDuration;
}
NSTimeInterval AQRecorder::GetCurrentTime() {
double timeInterval = 0;
AudioQueueTimelineRef timeLine;
OSStatus status = AudioQueueCreateTimeline(mQueue, &timeLine);
if(status == noErr) {
AudioTimeStamp timeStamp;
AudioQueueGetCurrentTime(mQueue, timeLine, &timeStamp, NULL);
timeInterval = timeStamp.mSampleTime * 1.0/mRecordFormat.mSampleRate; // modified
}
return timeInterval;
}
를 다음과 같은 방법을 시도했지만 첫번째 실제 녹화 시간 후 항상 적은 파일에 기록 된 패킷의 길이를 제공한다. 두 번째 것은 정확한 지속 시간을 제공하지 않습니다 (1-2 초 증가).
누군가가 같은 것을 구현하면 도와주세요. 감사합니다. .