Sound plays insanely fast

I'm trying to play a wave file via the javax.sound packaged classes. The sound I'm trying to play is about 5 secs long. However the below code actually plays it at about five times the speed, as well as making the pitch much higher (sounds like a tape recorder on fast forward). To add insult to injury, there's a burst of static at the end, and the program itself never naturally exits. Ideas?
package gov.nasa.gsfc.garnet.desktopclient;
import javax.sound.sampled.SourceDataLine;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Line;
import javax.sound.sampled.LineUnavailableException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.UnsupportedAudioFileException;
import javax.sound.sampled.AudioFormat;
import java.io.File;
import java.io.IOException;
* Utility for playing wave files on a user's system.
* @author SSAI
public abstract class SoundPlayer
    public static void play(File source)
            throws LineUnavailableException, UnsupportedAudioFileException,
            IOException
        SourceDataLine line = (SourceDataLine)AudioSystem.getLine(
                new Line.Info(SourceDataLine.class));
        AudioInputStream in = AudioSystem.getAudioInputStream(source);
        AudioFormat format = in.getFormat();
        line.open(format);
        final int READ_BUFFER_SIZE = (int)format.getSampleRate() *
                format.getFrameSize();
        byte[] buffer = new byte[READ_BUFFER_SIZE];
        line.start();
        int bytesRead = 0;
        while (bytesRead >= 0)
            bytesRead = in.read(buffer, 0, buffer.length);
            if (bytesRead >= 0)
                line.write(buffer, 0, buffer.length);
        line.drain();
        line.stop();
        line.close();
        in.close();
    public static void main(String[] args)
        File f = new File("/path/to/file.wav"); // this is on OS X, by the way
        try
            System.out.println("Starting playback...");
            play(f);
            System.out.println("play() returned");
        catch (Exception e)
            e.printStackTrace();
}

See this
http://forum.java.sun.com/thread.jsp?forum=31&thread=419813

Similar Messages

  • Sound plays too fast...

    Hi, I choose to render in 720p, I choose AAC 16,000Hz and the sound is accelerated. I can't figure out how to fix this.

    Excellent! My next suggestion was going to be to rip the Audio from the muxed AV file, with a program like Audacity, and then doing the Save_As to the 48KHz 16-bit PCM/WAV, but you beat me to it, and without the ripping step. Well done!
    Good luck,
    Hunt

  • When I play videos (on any website, using any browser) they play really fast and there is no sound.

    When I play videos (on any website, using any browser) they play really fast and there is no sound.

    http://forums.adobe.com/thread/1026022?tstart=0
    https://bugbase.adobe.com/index.cfm?event=bug&id=3216334
    https://bugbase.adobe.com/index.cfm?event=bug&id=3217331
    https://bugbase.adobe.com/index.cfm?event=bug&id=3219780
    https://bugbase.adobe.com/index.cfm?event=bug&id=3229264

  • Videos play too fast on ipad - sounds like super high speed mini mouse

    We just bought the ipad and when we play videos on vimeo or youtube they play at an ultra high speed like the fps is messed up - it sounds like a record being played too fast
    Is this our ipad or a setting - we are worried because we do not see the problem listed anywhere else.
    Thanks!

    Have your rebooted/restarted your iPad? you do that by pressing the Home and power/sleep button at the same time until the slider to power off the iPad appears. Slide the slider and when screen activity stops depress the two buttons again until the Apple logo appears. When the iPad completes rebooting try again to see if that solved your problem.

  • Sounds play faster than images when streaming a movie trailer on quicktime

    hi ...i don't know when it started but now when i go on the apple website to watch quicktime trailers the sound doesn't match the moving mouths! It's like watching a bad chinese movie lol what's going on? Why is the sound playing faster than the images?any idea on how to fix this?

    hi ...i don't know when it started but now when i go on the apple website to watch quicktime trailers the sound doesn't match the moving mouths! It's like watching a bad chinese movie lol what's going on? Why is the sound playing faster than the images?any idea on how to fix this?

  • FCP project sounds a little fast.

    I opened up my FCP project(running latest version of FCP Studio 2) and the audio sounded a little fast, like it was rushing a bit. The picture played along in sync. I played it a couple of days ago and the tempo seemed fine. What might be causing it to race?

    Funny thing and I thought this had happened before: although the computer had been on for a while, the FCP project had just been opened this morning. While it ran fast this morning, and leaving the FCP open all day (while I shopped for goodies for the 4th of July), I played the movie from the FCP timeline and it sounded "back to normal" in regard to audio speed. Since the media is spread out over several drives, maybe it had to be "woke up" a bit. As the project is only about 65 per cent done, I won't be trashing preferences just yet(did that once in the past and don't want to do that again!). And after it is completed and color corrected. I will consider the latest Quicktime update as well. I will export from the timeline when the project is done using the existing version 7.6, then install the latest and see if that makes a difference too.

  • Published for iOS, sound plays but no screen.

    Hi,
    I have completed a new game that runs great on Android - created using Flash Builder 4.5 and Flash Professional. I got all our Apple stuff out of the way and then also compiled for iOS. Then I deployed to my son's iPod Touch 5 via TestFlightApp.com. He installed and ran and we get the sound but no screen. I'd really like to finish debugging and then deploy this app for both droid and iOS at the same time (in the next few days). Can someone tell me why the SWF's that are the UI of the app are playing sound but not showing up on screen? How can I fix this problem?
    BTW, please forgive the fact that the site is under dev (will be completed and polished before go live), but you can get some idea of what the game is about at our web site: headshotgame.com.
    Best,
    Al

    Ooops, spoke too soon...
    After we recompiled all our FLA's to SWF's and added them as assets to our Flash Builder project, it did not work again (SWF sound plays but no graphics display). So, we went back to the earlier test solution and it did not work  either?!?
    Finally, we compiled using the quick compile selection of Flash Builder. The intro screen showed up all the sudden! But, none of the buttons work and you can't navigate to any other of the screens. Sadly, this is not answered and I don't know whether this belongs in the Flash Builder or the Flex forum as I don't know what is causing the problem.
    All of this works perfectly on Android. Same code on iOS does not work. Perhaps it's the fact that I'm testing on an iPod touch with iOS5?
    I have people waiting to test this app and help me get it live but I can't seem to get it to run on iOS. Please let me know if I can provide any other info to help you help me.
    Thanks!
    A summary of our problem:
    We have multiple SWF's that are compiled in Flash Pro that make up a larger mobile app that we built in Flash Builder.
    We add the Flash Pro SWF's to Flash Builder as assets of the project and use the Navigator to move between them with event listeners bubbling up from the buttons that are in the SWF's.
    There are many SWF's - most screens have multiple SWF's on them.
    All of this works very well on Android.
    The same project compiled for iOS creates an IPA file but when the IPA file is deployed to the device, none of the screens show up but the sound plays.
    There is only one way to get a (the first) screen to show on the device which is to set Flash Builder packaging method to "fast". Yet, getting the screen to show is useless as it won't allow you to navigate (and the SWF behaves differently in other ways compared to Android).
    I am testing on iPod and will recruit other iOS device users to test as well. The iPod I am testing on is an iPod touch with iOS 5.

  • CS4 premiere Imported .avi files play too fast

    Hi Guys
    I have a problem. I'm new to CS4 having used Adobe Premiere 6.0 in the past and I have never had this issue when importing .AVI files. What happens is that the file play fine in my windows enviroment and on all my players VLC,DIVX, Windows media player.
    But as soon as I import these files into my project at 29.97 frames the video plays really really fast and the sound plays at the normal rate. If I try to change the frame rate the sound also changes. Now here is the strange part. If I convert the files to MP4 they play fine! but the quailty of the video takes a massive hit as you know.
    I tried to convert the files to .MOV, MPG (which the program won't play) and most other types of video files but MP4 seems to be the only one that works! When I really want the higher quailty .AVI. Again the files play fine outside of CS4 Premiere and I have already converted them from a Panasonic AVCHD encode format.
    Please if anyone has any advise it would be great as I have to get this sorted for a x-mas present!
    Richard
    Running
    Windows Vista Ulimate
    4GB RAM
    Quad core Intel chip
    CS4 version 4.1.0

    First, work through all of the steps here http://ppro.wikia.com/wiki/Troubleshooting
    If your problem isn't fixed after you follow all of the steps, report back with the DETAILS asked for in the questions at the end of that link
    PS you are in the wrong forum http://forums.adobe.com/community/premiere/premierepro_current

  • Stop sound when another sound plays

    Hey guys,
    Using Flash Pro CC 2014, Actionscript 3
    I am working on a soundboard and use buttons that play sounds, and I want to make it that when a new sound plays, it automatically stops the current sound from playing, that way 2 sounds dont play at same time.
    But I also have a button that stops all sounds, I am using the "Click to Stop All Sounds" code under Audio and Video in the Code Snippets.
    So I am basically wanting to make sure I can do both, keep the stop all sounds button, but also have it when you press any sound button, it stops all sounds and starts playing the current button/sound. Any suggestions?
    BTW I am setting up symbols as buttons, not movie clips incase you need to know for coding, but I can switch to movie clips if its easier. I was just used to buttons on older versions of Flash for simple stuff like this.
    Thanks.

    Thanks for the reply, I am new to actionscript 3 but am a fast learner. Maybe I am doing this wrong, but when I add the code it simply stops the sounds, but it wont play the sound from the button that I just clicked on. I want it to play the sound button clicked on, and also stop any other sounds that are currently playing.
    For Flash 8, as2, I would add this to the button:
    on (press)
        stopAllSounds ();
    On as3, does it need to say this?
    button_2.addEventListener(MouseEvent.CLICK, fl_ClickToStopAllSounds);
    function fl_ClickToStopAllSounds(event:MouseEvent):void
        SoundMixer.stopAll();
    thanks for your help

  • Bounced tracks play too fast in iTunes

    This is a continuation of an old thread that was never resolved:
    http://discussions.apple.com/thread.jspa?threadID=853393
    Basically, nothing has changed. I can bounce my tracks from Logic, and they play fine everywhere except iTunes, where they play too fast. I can play them on my iPod in the car and everything works at normal speed.
    All my iTunes tracks (including the ones bounced from Logic) share the following characteristics:
    192 kbps
    44.1 kHz
    Profile: Low Complexity
    However, the Logic tracks play fast, whereas everything else plays normally.
    I have a standard G5 sound card, not a 3rd party one.
    I'm about to conclude that this is a standard limitation with Logic, that tracks created there cannot be listened to at regular speed in iTunes. Is that a known issue? Is this limitation by design?

    Sorry for the slow reply. Yes, that is the problem I'm having, and it's so weird, I thought maybe there was some wacky glitch in the program. Logic is not without its bizarre idiosyncrasies, as you've probably noticed yourself.
    Check this out for bizarre: I've bounced these tunes down to my iPod, where I can listen to them over headphones, in my car, etc, with the tracks playing at the right speed. However, if I plug that same ipod into my home stereo in the living room (where the laptop is also plugged in), and play those same tracks, they play too fast. I know, it doesn't make sense. But I'm not imagining it. It's completely crazy.
    In Audio Midi Setup my audio output is set for 44.1khz.
    Anyhow, the problem is less consistent these days. That is, sometimes I can bounce a track down and it plays right. Othertimes, not. I still haven't found the common denominator to this problem, but if I discover anything, I'll post it here.

  • Music/audio plays too fast

    using a new laptop (this compaq) and installed itunes. All music/audio, whether from a CD, or itunes or the audio from a website, plays too fast. I've tried lots of things -found a page in the support section (tried all except the driver thing) -- ANY THOUGHTS?? THis is driving me crazy and can't do anything w/ my ipod except listen to what's already on there!

    You may want to check your soundcard output in QuickTime. See this post for directions on the process: http://discussions.apple.com/message.jspa;jsessionid=aXxb7IZbMDPmI_4E?messageID=814726&ft=y&#814726
    And this Article: iTunes and QuickTime for Windows: Songs and other audio don't play correctly
    And before you do any of the above, make sure that you have all the recent Windows Updates from windowsupdate.com. Make sure you have the latest drivers for your particular sound card, and make sure you have the latest DirectX installed. Any of these could also cause this problem without QuickTime being the culprit.

  • Pulse audio plays too fast

    pulseaudio seems to be playing my sound way too fast
    Is there any way to slow it down?

    nevermind, fixed with the help of someone on the pulseaudio irc channel
    fixed by disable multirate locking and decreasing the multitrack internal clock samplerate to 48000
    by the way, does anyone know how to change the samplerate of the output stream?

  • Music is playing super fast  help?????????

    ever since i downloaded itunes 8 every song i play in itunes seems to be playing in super fast mode.... kinda sounds like alin and the chipmunks
    i tried reinstalling and other versions but still the same
    can anyone help me out with this???

    I'm having a similar problem. It started with iTunes 7, so I hoped version 8 would fix it. It's not my sound driver, because the files play fine in Media Player, and it's not all of the songs. About 20% of my songs just sound like garbage and play really fast. I've uninstalled and reinstalled, and that didn't help either. I've noticed a couple of the tracks on my iPod sound the same, so I am apprehensive about updating my iPod, fearing that it will screw up the rest of my music.

  • Sound.play() delay

    I am building a small game engine optimized for android, everything works fine, and I can render around 100 animated sprites with a decent speed, but I am stuck with the sound.
    when I play a sound there's a small delay, which is critical in action games, the first time I play a sound it runs fast, but after that there will be a delay.
    I am using the usual:
    var _mySound:Sound = new MySound();
    _mySound.play();
    I am using Flash CS5 with the android extension.
    and testing on Samsung Galaxy S.

    This is a known bug with the current version of AIR for Android, widely reported in the pre-release forums and logged with the engineers to be fixed.
    Adobe staff have directly acknowledged it on those threads too, which I interpret as a good sign that it's a priority.
    And yes, it is a pain!

  • Mp3 plays to fast

    I have this connected to a button with the mp3 in the same
    folder.
    When I run the swf file locally on my computer it works fine.
    But when I upload it to our server and acess it through IE, it
    plays very fast like listening to the chipmunks. Anybody know this
    is happening?
    on (release) {
    var my_sound:Sound = new Sound();
    my_sound.loadSound("lucille.mp3",true);

    martyredrocks,
    > ... when I upload it to our server and acess it through
    IE, it
    > plays very fast like listening to the chipmunks. Anybody
    > know this is happening?
    The chipmunks phenomenon happens when your sample rate isn't
    a multiple
    of 11,025, such as the common rates of 11,025 Hz, 22,050 Hz,
    or 44,100 Hz.
    Try resampling those MP3s from the original source audio at
    one of those
    sample rates.
    Out of curiosity, what version of Flash Player are you
    testing in? This
    issue was fixed (or should have been) with Flash Player 9.
    David Stiller
    Co-author, The ActionScript 3.0 Quick Reference Guide
    http://tinyurl.com/2s28a5
    "Luck is the residue of good design."

Maybe you are looking for

  • Calling Java in XSLT

    Hi, I am using the following blog to create and XSLT mapping and trying to call Java code from within XSLT. The only issue I am having is that I am not sure where should I put the .java and .class files. If I include both the files in a seperate fold

  • Passing input parameter to User Defined Procedures in ODI

    Hi I have to develop a procedure with an update query as follows Update Rec_Count set status as 'Y' where TableName = 'Name of the table' Here the 'name of the table' should be sent as input parameter while executing the package and this has 9 values

  • Having problem with "windows on top" in jre 6 update 12

    I'm having issue with the jre 6 update 12 with our Swing application. It works fine with update 11. The issue is that my JFrame is somehow getting set to be "always on top" once I've opened an closed a modal dialog from that JFrame. Here is the steps

  • IOS 8 AND CREATIVE CLOUD ISSUES

    I having problems with creative cloud since I've installed IOS 8, "simple commands like "open" are not working at all, I have to keep quitting illustrator / photoshop / indesign / etc

  • Google Maps 5.0.0 : 3D Nav.

    The New 5.0.0 is out Folks its Got 3D Nav. Compass and Improved Map Caching And Offline Navigation Rerouting if U lose Your Connection.  Download It See What U Think an Give a Post About it . I' ve Got it an I Like it Alott  Especially the Compass Mo