The duration of an audio file

I need to determine the length of my audio file. Right now I am using .caf files, but I can see how I might this to work with mp3s also.
Anyhow, I see this tidbit from the Apple Core Audio Spec:
mSampleRate
The number of sample frames per second of the data. You can combine this value with the frames per packet to determine the amount of time represented by a packet. This value must be nonzero.
That's looking good, except this will only tell me the duration of the packet. I can't find out how many packets my total audio file has. (And yes, this is a file, not a stream.)
What am I missing? Any help is appreciated.
Thank you.

Unless I am mis-interpreting the question this should work:
+(NSTimeInterval)getDurationForAudioFile:(NSString*)path
OSStatus status = 0;
AudioFileID audioFile;
NSTimeInterval seconds;
UInt32 propertySize;
propertySize = sizeof(seconds);
status = AudioFileOpenURL((CFURLRef)[NSURL fileURLWithPath:path],
fsRdPerm, AUDIOFILETYPE, &audioFile);
status = AudioFileGetProperty (
audioFile,
kAudioFilePropertyEstimatedDuration,
&propertySize,
&seconds);
return seconds;
Message was edited by: Amber Star

Similar Messages

  • How can determine the duration of an audio file

    Hi,
    i'm making speech recognition project using java. i can capture sound by michrophone and playback it. the type of the sound is .wav.
    my question is how to determine the recording duration (for example: determine the duration for 0.25 second) because i must recorded syllable,the assumtion is needed less than 0.5 second to say a word. and then.. can this wav file be changed into... binary or integer ?
    thanks for your help

    FYI I'm newbie in Java,
    Yes, I want to limit the audio file lengths to a certain value. What should I do?
    I have read wav file using an AudioInputStream, for audio format I'm using sampleRate = 8000.0F and sampleSizeInBits = 8. My friend said if I used 8 bit for sampleSizeInBit (resolution in amplitude) the binary file should be -128 till 127 in range according to the bit. I try this code and the result is binary file which is zero, positive, and negative.
    the code
    try{
    audioInputStream.read(audioBytes);
    for (int i=0; i<audioBytes.length;i++){
    System.out.println(audioBytes);
    catch(IOException ioe){
    System.out.println("Error"+ioe);
    I'm not sure that the code is right, but it works. Should I change the audioBytes into integer before? I try this code but it doesn't work.
    int a = new int[audioBytes.length];
    for (int i=0;i<audioBytes.length;i++){
    a[i] = new Byte(audioBytes[i]).intValue();
    this binary file has been printed in console (I’m using texpad). So, how I can write that to file.txt? I'm using FileoutputStream but it doesn't work correctly. Here is the code
    FileOutputStream fos = new FileOutputStream(strFilePath);
    {audioInputStream.read(audioBytes);
    fos.write(audioBytes);
    catch (IOException ioe){
    System.out.println("Error"+ioe);
    When I open file .txt is read as character like this üüüüüüüüüüüüûüüüûüûûû ||||||| ||||||| ||||||||||||||||||||||||||||| &#1746;&#1746;&#1746;&#1746;&#1746;&#1746;&#1746;&#1746;&#1746;&#1746;&#1746;&#1746; (like using alt plus number)
    Edited by: anasfr on Mar 19, 2009 9:02 AM

  • How to get the length of a audio file without play it ?

    Now I know a method to get the length of a audio file by play it:
    1 Create a Player, and add a ControllerListener
    2.Start the Player
    3.In the ControllerListener's controllerUpdate method, use getMediaTime() by receiving a EndOfMediaEvent
    However I think this method is not convenience, if I don't want to play it how I can get the length of the audio file?
    Is anyone can help me?Really thanks a lot !

    I got the answer here:
    http://forum.java.sun.com/thread.jspa?threadID=5149132&tstart=15
    I tried getDuration() before, but it always return a same time, I think maybe I didn't realize the player.

  • Vista - how do you make iTunes the default player for audio files?

    Having started using iTunes on a new Vista PC, I've found that it defaults back to Windows Media as the default audio file player every time the machine is rebooted.
    But worse than that, I cannot find any option to make iTunes the default player for MP3 files - under the Vista settings, the ONLY option offered is Windows Media: there is not even a box to tick for iTunes.
    Have others found this? Is there any way around this?
    (I thought that Microsoft was legally precluded from making these kind of enforced settings now???)

    Although I now seem to have successfully made iTunes the default player for audio files, iTunes has started putting up this message:
    "The iTunes Music Library file cannot be saved. You do not have enough access privileges for this operation."
    A quick scan of the forum shows this problem has come up quite a few times, but I'm far from clear if there is a definitive answer/solution. I am the administrator for the computer. It sounds worrying that the Library file is not being saved - should I be worried?

  • ITunes doesn't recognise iPod as the default player for audio files.

    A few weeks ago my husband completely re-installed our laptop, without properly looking at how to backup my iPod touch. Everything was lost and I have had to start again, however the system still comes up with this message each time I plug the iPod in:
    iTunes has detected this is not the default player for audio files. Would you like to go to the Default Program Control Panel to fix this.
    I go to the Control Panel, but have no idea what to do.
    Can anyone please help me?
    I have not upgraded to version (4.0)
    Thanks in advance.

    Hello Geordie81,
    And welcome to Apple Discussions!
    Are you sure it wasn't referring to making iTunes the default application for audio files as described in this Apple support document? Worth a shot anyways.
    [iTunes for Windows: How to make iTunes the default application for music and audio files in Windows Vista and Windows 7|http://support.apple.com/kb/HT3202]
    B-rock

  • How do I change the length of an audio file?

    How do I change the length of an audio file without changing the actual recording?
    I want to aligne start and end points to the rest of my project.

    Well, yes and no. I have tried the Bounce track in place function, but it did not do what I was after. However, today I got an idea that solved the problem. I copied the region I had punched in several times. Then I used the Bounce track in place function. This made a track that was just as long as all the other tracks. Finally I silenced the audio "clips" that I had used to make the region longer. I have now 24 tracks to transfer to the Alesis HD 24 that starts, and ends, at the exact same point. This will suit the Alesis software just fine, I think.
    Thanks for the tips.

  • "could not open score because the project has no audio files"?

    I just purchased the urban bundle from Resource Central, and uploaded it in "Bridge", I double-clicked the "sbst" file
    to import to soundbooth and I get this, "could not open score because the project has no audio files"? when I single
    click it in bridge the audio plays fine and shows the 4.61 file size, so there are audio files, can you tell me whats
    going on?

    I FOLLOWED EVERYTHING YOU SAID, AND IT WORKED LIKE A CHARM
    YOU ARE TRULY A PROFESSIONAL AND A SCOLAR!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    MUCHO THANKS. THANKS FOR NOT GIVING UP ON ME. YOU ARE THE
    BEST!!!  I GUESS MY PREVIOUS EXTRACTION THE FIRST TIME I TRIED
    DID NOT WORK, BUT FOLLOWING YOUR STEPS GOT IT GOING.
    THANK YOU ONCE AGAIN, NOW I NEED TO GO SEE "DOCTOR BOSLEY"
    FOR SOME HAIR REPLACEMENT BECAUSE I PULLED IT ALL OUT TRYING
    TO FIGURE OUT WHAT THE HELL I WAS DOING WRONG. THANKS AGAIN BRO.

  • "An error occurred while updating the default player for audio file types"

    Getting ready for a deployment of version 9.2 of iTunes for 1400+ users.
    Getting this error when a 'normal' user goes into Edit/Preferences of iTunes and makes no changes.
    "An error occurred while updating the default player for audio file types. you do not have enough access privileges for this operation."
    I've elevated privileges of the C:\program files\itunes directory for this user to Full Control however problem remains.
    Tried to modify the folder to remove 'read-only', as found this suggestion on here, but read-only keeps applying itself.
    User has full rights to the location of the media as specified under Advanced Tab. If I tick 'Set as default media player' and remove tick and then click OK I do not get the error. From what I've read it's affected older versions of iTunes also.
    Doe anyone have any other suggestions?
    Thanks in advance.

    I had a similar issue. Turned out that - somehow - one of the directories or files in my iTunes music folder had gotten set to read only. Fixing it was easy.
    Go to Edit/Preferences.
    Choose the Advanced tab
    in the General subtab select the contents of the box labeled "iTunes Music folder location"
    Click Start, choose Run
    Paste the location
    Press the button to move up one level
    Right-click the music folder, choose Properties
    If this is your problem, the read-only box will be a solid color or checked. Set it to empty and choose the default "apply to folder and all subfolders and files." This will set everything in there readable, which after I did so I stopped getting the error.

  • Upgraded to 10.3.1.55, now can't set iT as default player,"An error occurred when updating the default player for audio files types.  You do not have enough access privileges for this operation." How to fix?

    After I upgraded iTunes, iTunes doesn't recognize CD in the drive, apparently isn't the default player.  It won't let me set iTunes as the default player, I get the error message "An error occurred when updating the default player for audio files types."  I tried Whitesides' remedy (changing Read Only status in folder in Windows) but it didn't solve the problem.  Any suggestions?  Thanks.
    J

    Oddly enough. I think I just solved it. It looks like, for some reason, my computer has about 8 different "iTunes music" folders, and I've been saving my music to the wrong one. Neat. Music now imports and plays as it should. Copying things over is going to be so fun tonight!

  • Do i need a special licence to sell music in the Apple AIF/AIFF audio file

    hello im a music producer, i sell customer non exclusive licences to my musical productions my question is Do i need a special licence to sell music in the Apple AIF/AIFF audio file. like i know for the Mp3 File format if i make a certain amount in sales or whatnot i would have to pay the owners of the MP3 file format royalties so im wondering if apple has some restrictions on using the apple AIFF/AIF file format in commercial digital downloads etc.
    also wondering if there is any information regarding my issue anywhere on the apple site or if its in logics paper booklet or something, 

    I would think that if there is any information available from Apple, it would be found on their legal page. http://www.apple.com/legal/

  • Where are the FCPx and iMovie audio files located in fcpx 10.1

    I updated to FCPx 10.1 a couple days ago and have now realized that none of the FCPX or iMovie audio files are showing up under the Music and Sound button. Does anyone know where they've run off to?

    Try this trick by BenB:
    https://discussions.apple.com/message/24199975#24199975
    Al

  • Viewing total duration for multiple audio files

    I need to be able to view 'total duration', when selecting multiple audio files, e.g. 10 audio files, total duration 42.03. I can't find a way to do this and so far, all I've been able to do is view individual audio file durations, then total them manually (which takes far too long, for what I need to do). I've previously been a Windows user, and this is instantly viewable in Explorer.
    I'm new to OS X, and really need to be able to do this for my job. Can anyone help??
    Thanks in advance, Marc

    Here's an image to explain better:
    http://img216.imageshack.us/img216/3241/playlisttotaltime.jpg
    However the total time isn't 100% accurate, because I believe iTunes is adding some extra seconds for the gaps in between songs.

  • ITunes lost all the names of my audio files

    I can appreciate that there are some people who need to have organisation forced upon them because they are incapable or too lazy to do it for themselves. I personally hate apps which take control of my computer or file system and put things where I can't find them.
    I have always had my iTunes prefs set to manually manage my audio files. I record messages from our Church services to put on the internet for people to listen to who are unfortunate enough not to be able to attend the service, for whatever reason. Each recording has a different speaker and message heading, which I manually type onto each file after I have converted it from AIFF to MP3. The files are all called 01 Track 01 in their default state from our CD recording equipment.
    I had over 1 year's worth of speakers in a folder with, on ocassions, 2 - 3 speakers per week. On one particular day last week, I was doing something on my computer (can't remember what now) but a message appeared which said something along the lines of - 'can't complete your request because your iTunes library is not organised, do you wish to do that now?' and without thinking I pressed the ok button and the task completed.
    It was not until the next Sunday when I went into the folder to retrieve the file called 01 Track 01 from amongst all the other named files, that I found over 100 files all with the titles 01 Track 01 1, 01 Track 01 2...3, etc etc. - so much for Apple's brilliant organisation, now I will have to go into each one individually and try to recognise each speaker's voice and wait until he announces his reading before I can name the files to something I will recognise in the future.
    iTunes asked if I wanted to 'organise' my files - not rename them, I am so angry about this and I'm guessing there isn't an easy way to fix this - OK, I use Time Machine to backup my discs - but there is 100's of MBs of data to transfer over when it is only the names I need - I KNOW, somebody is going to tell me that it would surely still be quicker to do this than retype all the names - I WILL do this if there is no other option, but I'm hoping that Apple or somebody will be anble to suggest a quick way for me to get all the names back onto the right files.
    Any suggestions anybody?
    Thanks

    iTunes: Specific update-and-restore error messages and advanced troubleshooting

  • Slideshow, how to make clip the same length as audio file?

    Hi
    I've got several PowerPoint presentations and need to make an MP4 video file for each of them. I know how to export the slides as still images, and I also have the audio files broken up into individual mp3 files that match each slide.
    I'm trying to figure out the most efficient way of getting the slides and audio files synced in Premiere Elements.
    Yesterday I imported all of the png images and mp3 audio files into my project. But I had to individually add each image, followed by the mp3, and then in the timeline manually stretch the image to make it last the same length of time as the audio file. It was rather tedious and I have a lot of presentations with many slides to work with. I'm sure there must be some better way to make all of this happen, right?
    Can anyone help me out here?
    1. Is there a way to make the image clip match the time of the audio clip?
    2. Is there a way to import all of the audio and image files at once (given they have the same names) and have PE automatically associate the image clip with the audio file?
    Thanks, Derek

    1. You can place the audio file in the Audio 1 track of the timeline first (Timeline, not sceneline)
    2. Next drop the image to where the audio file starts. Now press "\" key
    3. Drag the end of the clip to exactly where the audio ends. Whe you are near the end of the audio with the drag it should simply stick to it.
    4. Group the audio and image file together (Right click and select group after selecting both these together)
    5. Select the clip and do a right click and use the Fade-In and out option. You can fade in the video and let the audio simply continue. This makes it look and sound good.
    6. Place the next audio file and go on doing the same till all of them are done. The grouping step is not needed but when you keep working with PRE, you might just thank me for it!
    I tried all these steps just as I was typing this post, so I can tell you for sure that PrE10 works as if it is designed JUST for this use case. So hoping you get to complete the project on time and with good quality!

  • How do I add a pause to the beginning of TTS audio file ?

    Hello,
      I am using Captivate 6, and I am having adding a pause to the beginning of my TTS audio file.  I would like to like up the text with the video.  I've attached a video to show you the problem.  Thank you!

    Sorry but your video does not seem to play.
    I was going to suggest, that what you want to do is actually very easy. If you have already created the TTS audio file and have it on the slide, just drag the audio file to the right on the timeline for a second or two. That will delay the start of the audio just the same way it does for any other object you want to appear at a given point.

Maybe you are looking for