Get Total Duration/Length of Selected Audio Files

Hi there,
How can I create an AppleScript that adds the total length/duration selected audio files.
I know how I can get the duration of a single file, doing this:
set a to choose file
do shell script "afinfo "&quoted form of (posix path of a)&"|grep duration"
But I wanted to have the total length, if possible in minutes, of all selected audio files.

There are numerous approaches, but since you've already started with afinfo, I'll keep with that.
The first step is to extract the actual duration from the afinfo output:
set duration to (word -2 of (do shell script "/usr/bin/afinfo " & quoted form of (POSIX path of a) & "|grep duration")) as number
now you can just wrap this in a loop, adding up the numbers as you go. This will end up with a total number of seconds, and a little math gets you the minutes:seconds format:
-- initialize our counter:
set total_duration to 0
-- note you can now select multiple files
set file_list to choose file with multiple selections allowed
-- and loop through them
repeat with each_file in file_list
          try
                    set this_duration to (word -2 of (do shell script "/usr/bin/afinfo " & quoted form of (POSIX path of each_file) & "|grep duration")) as number
                    set total_duration to total_duration + this_duration
          end try
end repeat
-- now convert your seconds to minutes:
set num_minutes to total_duration div 60
set num_seconds to total_duration mod 60 as integer
display dialog "Total duration is " & num_minutes & ":" & (text -2 through -1 of ("0" & num_seconds))

Similar Messages

  • 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.

  • 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.

  • HT3775 How do I get QuickTime Player to read ogg audio files?

    How do I get QuickTime Player to read ogg audio files?

    For Quicktime player to play it, it needs to be converted
    to one of the formats listed here:
    http://support.apple.com/kb/HT3775
    Otherwise, you will need to use different player software.

  • I am having a difficult time getting the duration of multiple selected clips. The duration display only will display the time for one clip.  Yes, I know I can add them up myself, but why?  :-)

    I am having a difficult time getting the duration of multiple selected clips. The duration display will only display the time for one clip not multiple clips.  Yes, I know I can add them up myself, but why?  :-)
    I am using imovie 10.0.6

    For reasons that you would have to ask Apple for they decided not to allow the precise position of the playhead to be shown in iMovie 10 (unlike in FCP 10.1.x).
    Geoff

  • Sample editor doesn't open selected audio file in 8.0.2

    Hey there.
    I've just upgraded to Logic pro 8.0.2 from 8.0. When i drag an audio file (a) into the arrange page and then double click on it, it says "nothing to display". It then randomly displays the file (a) but when i double click on another audio file (b) it opens up audio file (a).
    Very strange behaviour that surprisingly didn't occur in Logic pro 8.0.
    Any suggestions would be really appreciated.
    Thanks

    Hey Jorge.
    Thanks for the suggestion. I've actually had to re-install the bug ridden 8.0.0 version to get it to work. Never thought i'd be saying that
    I haven't updated it yet as i need to get some work done before i waste another day trying to sort out mysterious errors.
    Thanks anyway
    Rowan

  • How to get total number of pages from .doc file without using Office interop?

    Hi,
    Kindly help me in getting the total number of pages from a .doc file not .docx file using C#. I know how to get by using Office interop but I do not want to use Office interop.
    So, without office automation in C# let me know how to get the total number of pages from a .doc file.
    Regards,
    Ashok

    Hi Ashok,
    >> I know how to get by using Office interop but I do not want to use Office interop
    Could you tell us why you don't want to use Office interop?
    As far as I know, this is the easiest way to achieve.Hmmm,this is my answer
    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.pagenumbers.startingnumber(v=office.14).aspx
    Best regards,
    Kristin
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Encode selected audio files?

    Does anyone know what this means or where I can read about this function?
    I don't see anything happening and I don't know what it is supposed to do.
    Thanks in advance!

    Jim,  Thanks for the reply!  I understand a little more now, but I am wondering what the purpose of 'encoding' really is?  Why would I need to encode a file?
    As an example, I would like to take a weav file and create an mp3 with it...will this method do that?
    Thanks again.

  • How do I get iTunes U to play all files, right now it stops after each audio file and I will have to manually select the next one.

    I am unable to find a way to get iTunes U to play all audio files one after the other without me manually playing each one of them.

    Best I've managed is to create a smart playlist in iTunes with the album set to the title of the course.  Have the smart playlist update automatically so that any new postings from the course are included within the playlist. After that you should be able to play the playlist and have all the audio files play one after the other.  Hope it helps!

  • Get the duration of all mp3 files inside a directory

    Hello everyone,
    I am working on a little project done with swing. Since I need an mp3 player inside my swing application, I found a really good solution with JavaFX 2. I have never worked with JavaFX before, therefor it seems to me a little bit strange on some parts.
    Anyway.
    I created a button on my application and as soon as somebody presses that button, the application should scan recursivly a unique directory for mp3 files and store the information of artist, title and track length into a database.
    The mp3 player I created is based on the example from this page:
    http://www.java2s.com/Code/Java/JavaFX/Mp3playerwithmetadataviewandcontrolpanel.htm
    I understand the source code for most parts, but some behaivors are not really clear to me. My thoughts about getting the complete length of the mp3 file was
    media.getDuration
    or
    mediaplayer.getTotalDuration
    but both results are NaN if I call .toMillis();
    Instead I need to create a listener (why?)
    private class TotalDurationListener implements InvalidationListener {
        @Override
        public void invalidated(Observable observable) {
          final MediaPlayer mediaPlayer = songModel.getMediaPlayer();
          final Duration totalDuration = mediaPlayer.getTotalDuration();
          totalDurationLabel.setText(formatDuration(totalDuration));
      }and register this listener on the mediaplayer
    mp.totalDurationProperty().addListener(new TotalDurationListener());I can image that the mediaplayer can "host" several media objects somewho and the listener is called as soon as a new media will be added to the mediaplayer in order
    the calculate the overall duration.
    When is this listener exactly called and is there no other ways to get the total length of the mp3 file?
    Here is a minimal example which should work without any external libs
    package de.hauke.schwimmbad.application.playground;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.io.File;
    import java.util.ArrayList;
    import java.util.List;
    import javafx.application.Platform;
    import javafx.beans.property.ReadOnlyObjectWrapper;
    import javafx.embed.swing.JFXPanel;
    import javafx.scene.Scene;
    import javafx.scene.layout.BorderPane;
    import javafx.scene.media.Media;
    import javafx.scene.media.MediaPlayer;
    import javafx.scene.paint.Color;
    import javafx.util.Duration;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.UIManager;
    public class Testing10 extends JFrame {
         private MediaPlayer mediaPlayer;
         private final ReadOnlyObjectWrapper<MediaPlayer> mediaPlayerWrapper = new ReadOnlyObjectWrapper<MediaPlayer>(
                   this, "mediaPlayer");
         public static void main(String[] args) {
              try {
                   UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                   new Testing10();
              } catch (Exception ex) {
                   System.out.println(ex);
         public Testing10() {
              super();
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              setLayout(null);
              setSize(500, 500);
              setTitle("Testing");
              setLocationRelativeTo(null);
              setResizable(false);
              JButton button = new JButton("Scan");
              button.setBounds(10, 10, 150, 30);
              add(button);
              button.addActionListener(new ActionListener() {
                   public void actionPerformed(ActionEvent arg0) {
                        scan();
              final JFXPanel fxPanel = new JFXPanel();
              fxPanel.setBounds(30, 80, 300, 300);
              add(fxPanel);
              Platform.runLater(new Runnable() {
                   public void run() {
                        initFX(fxPanel);
              setVisible(true);
         private void scan() {
              File directory = new File("C:\\dev\\mp3");
              List<File> mp3Files = new ArrayList<File>();
              for (File file : directory.listFiles()) {
                   if(file.getName().endsWith("mp3")) {
                        mp3Files.add(file);
              for (File file : mp3Files) {
                   System.out.println(file.getAbsoluteFile());
                   getLength(file);
         private Duration getLength(File file) {
              if(mediaPlayer != null) {
                   mediaPlayer.stop();
              final Media media = new Media(file.toURI().toString());
              mediaPlayer = new MediaPlayer(media);
              mediaPlayerWrapper.setValue(mediaPlayer);
              if(media.durationProperty()==null) System.out.println("durationProperty ist null");
              if(media.durationProperty().get()==null) System.out.println(".get() ist null");
              System.out.println("---> " + media.durationProperty().get().toMillis());
              return media.getDuration();
         private void initFX(JFXPanel fxPanel) {
              BorderPane root = new BorderPane();
              Scene scene = new Scene(root, Color.ALICEBLUE);
              fxPanel.setScene(scene);
    }The other question is why do I need a listener for the meta data to be changed in order to get the meta data?
    media.getMetadata().addListener(new MapChangeListener<String, Object>()Why can't I call something like
    media.getMetadata() --> returns a filled map?
    The metadata problem is not included inside the example from above.
    Sorry for my english but I hope everybody can understand the issue.
    Many greetings,
    Hauke

    The nature of the Media class is that it accesses it asynchronously. This means that when you create an instance of it, and then immediately query it, the data you want may not be available yet. This is all in the Javadoc, see the doc for Media:
    The media information is obtained asynchronously and so not necessarily available immediately after instantiation of the class. All information should however be available if the instance has been associated with a MediaPlayer and that player has transitioned to MediaPlayer.Status.READY statusSo you could associate the Media with a MediaPlayer, and then wait until it goes to the Status READY, and then read the length of the Media.
    As for your 2nd question, getMetadata() returns a Map. You can just loop through it:
      for(Map.Entry<String, Object> entry : media.getMetadata()) {
        // etc
      }However, the same restrictions apply as with Media -- you will probably need to wait before the information is available -- that's why the Listener approach works, because it will notify you as soon as the information is added to the map.

  • 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

  • Slide Action on Exit Cancelled by Length of Audio File

    Captivate 8.0
    Responsive Project
    Status:  Solution to problem works but makes no sense
    Problem:  Slide actions on exit designated in the Properties Inspector do not function.  Although the "jump to slide" action was selected, the transition at the end of the slide moves to the next slide. I encountered this problem as I was developing a series of slides that would supplement a single beginning slide.  Using click boxes I wanted the learner to be able to click on an item, go to a slide with more detail, then return to the original list on the starting slide.  I set the supplemental slides up in the Property Inspector--Actions to "Jump to slide" and selected the beginning slide number.  When I ran the project, the click boxes moved to the correct slides but the supplemental slides did not return to the beginning slide.  They only transitioned to the next slide.   
    Solution:  This makes no sense to me and is the source of my question.  I'm using text-to-speech as a temporary method of making a rough cut at timing while I am waiting on narration files.  The audio files created by text-to-speech usually run to the end of the slide and are exactly the same length as the slide.  Grabbing at straws to fix the problem, I added 0.2 secs to the slide length so the slide timing was slightly more than the audio file.  Voila!  The selected action (jump to slide X) functions as expected.  I made the same change on the balance of seven slides and the entire routine works as designed.  I have not tested slides using imported narration or narration recorded within Captivate to see if the same problem presents. 
    Why would this be?  Why would the length of an audio file prevent an exit action from functioning? 

    Lilybiri answered this on another question discussion 
    "Slide on exit action conflicts with button action in Captivate 5.5"

  • File Not Found bug with long audio file names?

    Hello -
    Crazy problem. I'll probably post way too much information, but I want to make sure I cover everything. Help!
    We run Logic Studio/Logic 8 on multiple 10.4.10/11 computers - G5 Power PC, new intel iMac, intel mini, G4 laptops. We are working on an audio post job using very messy OMFs that were prepared in Final Cut. We had problems opening them in Logic, so we opened the OMFs in Soundtrack Pro, exported to AAFs, and opened those in Logic.
    The sessions look fine in Logic now (all files relinked), and the session is consolidated - ie, all files are local/in the project folder's Audio Files folder. I see this in the Audio Bin and can confirm in the finder.
    Here's the problem. With the sessions closed:
    (A) I renamed the project folder by adding an asterix to the front of the folder name, and changed the color label of the folder in the finder in order to mark it as the original folder.
    (B) I made a copy of the whole folder (session files & audio files) in order to have something to work from and not mess up the original. When I opened up the session in the new folder, it immediately said audio file not found, do you want to search, locate, or skip. It couldn't find the file in a search, and obviously when you skip, then skip, then skip all, it opens the session with the data (regions are there but grayed) - so all the audio files are orphaned.
    So when I try to locate the file, here's what happens. . . The audio file names are really horrendously long (must be some artifact of working in Final Cut). We're talking: "1087-001A SERG AIRPORT WAITING * 1-1channel_00044D02AA9- 363A-4CC5-A86B-0741023DB062.aif" - one bazillion characters.
    So the audio file locate dialog box truncates the name of the file that's missing by using the first 20 characters or so, and then a "#" character, and then some random string of 3-6 characters that is not at all related to the file name. So who knows which of the 4-30 SERG AIRPORT files is supposed to go there!
    Obviously if this were a 2 minute session file of 10 files or something, we could figure it out and relink everything, but we're talking about a feature-length session with a bazillion files.
    (C) Okay, so I tried to open the original session, in the folder that I had renamed by prefacing the original name with an * and changing the color of the folder. But I started to get the file not found errors. OH GEEZ. So I didn't save. I re-renamed the folder by taking out the * and changing the color label back. Then I tried to open the session again, but I still kept getting the file not found problem.
    I have to stress that I didn't move any of the audio files, or change ANYTHING in the session.
    So I thought - is all of this because I tried to open a new instance of the session, in a new instance of the folder? Is it because I renamed the folders? Normally you can rename folders, even session names, no problems, and Logic corrects the paths to the audio files!
    (D) So, crap. I reopened the original AAF file in logic and saved it in a new place. I closed the file, reopened it, closed, reopened, just to make sure everything was working! I checked the location of the files in the audio bin, and everything was great.
    (E) So now I copied the folders to an external hard drive to be able to work on another computer. But when I tried to open the sessions on a new computer. . . You guessed it, nada.
    So. . . the questions are:
    (1) Those original sessions that now will not work - is there anything I can do to recover their functionality? We had work in there that I would prefer not to lose. . .
    (2) Is this a known bug having to do with the length of the Audio File names?
    (3) How do we get over this? My only idea so far is we could select all in a working logic session and say "Audio Tracks names to regions" or something and will that change the actual file names on teh computer? Then hopefully things would work on mulitple systems. . .
    Okay. HELP! Thanks!
    Polly

    OK I got it.
    It is necessary to use prefix "file:///" before file name.
    Thanx everyway.

  • Error message: "the previously selected audio interface is not available"

    HELP?!?!?!?!?
    I'm stuck, and I can't go forward. Here's my issue:
    I've bought a Focusrite Saffire LE, a simple firewire audio interface, for use with my Logic Express 7 (with all the latest updates). I run the setup assistant and select my saffire as the audio interface to use, and then when logic runs I get the message "the previously selected audio interface is not available" and it defaults to my Macbook Pro's internal microphone and speakers.
    Just for sanity I've tested the audio interface with garageband and it's fine. My other audio apps aso run fine using the saffire as the audio interface. The setup assistant for logic has no problem finding the saffire, so why does it get rejected as soon as logic starts?!?!?
    Please - this is driving me crazy.

    I asked Focusrite for some help, and they said it should work (which I knew) and made some suggestions. Here's their email:
    "Saffire LE should work fine in Logic Express.
    Try resetting your logic preferences. Go to Logic > preferences > initialise all except key commands.
    Do you still have the same problem?
    Do you have any other firewire devices attached?
    Have you had any other interfaces installed in the past?"
    All good suggestions, but so far no luck.
    Has someone else got the same config as me? (15" Macbook Pro and focusrite saffire le)?

  • Where does Keynote store the audio files in a presentation

    I have slides with individual audio files. When I import or attach the file and then save the presentation, it changes the file name to .mov extension. Where does Keynote store those files? I would like to edit the saved Keynote version, but cannot locate the .mov file!

    I'm not exactly sure of what you want to do, and I'm not sure if my answer is the most efficient, or even wholly correct, but here goes ...
    When you save a KN presentation (a KN doc) which includes an audio (or movie) file, you can save it 2 (3?) ways: either without or with the file being copied into the document, or as a "package". In a test file I just made with 3 white slides (title, slide with song, second slide with song) the results:
    without: 3.8 MB; with: 9.4 MB; package: 9.4 MB. The essential difference, aside from size, is that if saved without, if you play the KN on another machine which doesn't have those audio files on it, the audio won't be there. To make the KN truly portable, you must save with, or as a package. (I'm not too sure of the concept of package in KN. In PP, saving as a package means you end up with a folder, which contains the PP and the media files, each as separate entities. Saving a KN package yields not a folder but a file, which looks to me identical to the result achieved by simply saving with, and seems to behave identically, as well.) The audio file you used will in any case remain where it was before you used it, but, if the KN doc is saved with, or as a package, a copy of it will go into the KN doc.
    But then, what do you mean by "edit"? What do you want to edit, the KN presentation, or the audio file within it? If the former, I don't understand where the problem might be. If the latter: using the QT inspector within KN, you can change the length of the audio file (where in the song it starts and stops), whether to start it on click, or automatically after transition, or to loop it. If you wanted to do some other, more exotic audio editing, like reverbs or other effects, I'd do that on (a copy of) the original audio file (found wherever it was before) with another app (GarageBand, for instance), and then I'd replace the first, non-edited, version of the audio file in the KN doc with that.
    Have I missed something?
    Message edited by gbdoc: maybe someone will chime in to clarify the difference between "saved with" and a "package"

Maybe you are looking for