Latency free MMAPI audio recording and play.

ByteArrayOutputStreamEx output = new ByteArrayOutputStreamEx(300000);
            Player recorder = null;
            RecordControl rc = null;
            try {
                recorder = Manager.createPlayer("capture://audio?encoding=amr");
                recorder.addPlayerListener(this);
                recorder.realize();
                recorder.prefetch();
                recorder.start();
            } catch (IOException ex) {
                ex.printStackTrace();
            } catch (MediaException ex) {
                ex.printStackTrace();
            while(stopThread != true){
                try{
                    output.reset();
                    rc  = (RecordControl)recorder.getControl("RecordControl");
                    rc.setRecordStream(output);
                    rc.startRecord();
                    sleep(5000);
                    rc.commit();
                    ByteArrayInputStreamEx playerInput = new ByteArrayInputStreamEx(output.toByteArray(),output.size());
                    Player playit = Manager.createPlayer(playerInput,"audio/amr");
                    playit.start();
}Quick explaination :
The purpose of this code is to record the user and immediately play the sound , with minimal latency in between, in continous repeating loop.
ByteArrayInputStreamEx and ByteArrayOutputStreamEx are my versions of the streams that -do not - use dynamic memory, just reuse the same original buffer (300k in this case)
Another tweak I used to avoid reallocating memory for each call is I leave the recording player working without stopping/starting it and just reset the record-control.
Problem is, for some reason the recorded data doesn't really get reset ...
Any ideas ? what did I do wrong?

Another tweak I used to avoid reallocating memory for each call is I leave the recording player working without stopping/starting it and just reset the record-control.
Problem is, for some reason the recorded data doesn't really get reset ...
Any ideas ? what did I do wrong?DannyZB,
What do you mean that the recorded data doesn't get reset?
Does the player play anything at all?
I think you should create and call realize() on player initially outside of the loop and then start() and stop() in the course of your loop. You should also have 1 RecordControl obtained outside of the loop.
Daniel

Similar Messages

  • Recording and playing Audio at the same time

    Hi,
    Having problem with a MMAPI imp.
    The simplest way of doing it is to start one thread playing a audio file of any kind.. As it is playing start a other thread that start a audio recording.
    As soon as the audio recording is allowed to record (Security promt) the audio playback stops. And the playerListstner sends a END_OF_MEDIA event.
    So my question is: Is there a way of doing playback and recording at the same time or is this a limit on the phone or the MMAPI?
    This has been tested on Nokia N90 and SE W550i with same reults
    Cheers
    Kenth

    i also desperately need to record and play audio at the same time.. i have a term project, i am develeoping a karaoke player in j2me and it is supposed to capture the voice at the same time background song is played.. and it is also supposed to grade the singer according to the pitch of voice.. please help me about recording and playing audio at the same time...

  • Recording and playing audio files

    hi, is there a way by which one can record and play an audio file in java ?? I am doing a project in Voip but I can't find any help in this matter(actually i am a newbie in java ) .. can anyone please tell me how to proceed?
    Edited by: streetfi8er on Jun 28, 2009 2:47 AM

    >
    hi, is there a way by which one can record and play an audio file in java ?? I am doing a project in Voip but I can't find any help in this matter(actually i am a newbie in java ) .. can anyone please tell me how to proceed?>You could not find anything on ['java audio'|http://lmgtfy.com/?q=java+audio]? Where did you look, underneath the bed and in the back yard?
    Note that you might help dispel my impression that you are lazy, by applying the shift key once at the start of each sentence.

  • Please help me with recording and playing audio simultaneously!!!

    Right now I can either play the incoming stream OR record it. I tried making Clones for datasource like :
    DataSource clone1 = Manager.createCloneableDataSource(originalSource);
    Then I pass it to these 2 classes:
    new playThread(clone1).run;
    new recordThread(clone1).run;
    playThread is a Thread class that will take the cloned datasource and then plays it while recordThread will record the incoming datasource. Here is what happens when i run them one after another:
    When I run playThread before recordThread I get ACM driver error. But if I run the recordThread before playThread the playThread's playerWindow shows up and plays for a split second then stops; The recordThread does record all the incoming stream though... Here are my questions....
    1. Anyone know what my problem is? is it resource alocation? Threading problem?
    2. Did I use the clone datasource correctly? I tried making clone1, clone2 but those didnt work well either...Should I do anything to the clones for record and play? all I did was pass them to the 2 classes and those classes just use them straight out without proccessing or anything...
    Please help me out!!!! thanks a bunch!

    i dont think it is... i tried the clone thing but samething happened... it might be a Thread problem since when i put those together sometimes record runs sometimes player runs... and at the end i get "ERROR while querying ACM driver's information" error..... i am really confused...
    DataSource clone1 = Manager.createCloneableDataSource(originalSource);
    DataSource clone2 = Manager.createCloneableDataSource(clone1);
    playerThread play= new playerThread(clone1);
    recordThread record= new recordThread(clone2);
    record.start();
    broad.start();
    anyone can help is appreciated

  • Recording and playing back

    Hi, I have question about recording and playing back.
    I am going to record by AudioQueue and to play back by MPMoviePlayerController.
    My code can record by AudioQueue.
    But, It can not record After playing back by MPMoviePlayerController.
    Is Anyone who had same problem and solved it.
    Please tell me resolution method.

    Hi
    Welcome to Apple Discussions.
    We don't get very many questions about Core Audio here so if you don't get any response, you can try the Apple emailing list for Core Audio:
    [email protected]
    The list is very friendly and I'm sure someone there will be able to answer your question.
    Bob

  • Is it possible to record and play at same time in swift, is there a option to record without storing the file

    I am making a microphone, is it possible to record and play at same time in swift, is there a option to record without storing the file

    Its pretty simple with FMS. You just need to do following things:
    Publish using FMLE with following settings: (just telling which are needed , rest you configure based on your needs)
    Video codec: H.264
    Audio Codec: <of your choice>
    Server ip: rtmp://<server-uri>/<app-name>
    Stream Name: mp4:<stream-name>.f4v
    Application : Server-side code
    application.onPublish = function(myclient,mystream){
         mystream.record();
    application.onUnpublish = function(myclient,mystream){
         mystream.record(false);
    Have a client , which subscribes in following live mode:-
    ns.play("mp4:<stream-name>.f4v",-1,0,true);   // this is subscribing in live mode
    In this way even if file is recorded, your clients are subscribing in live mode so all will be in sync.
    Now if you want to disallow any clients who will try to subscribe to "recorded" file when live event is going on, you can achieve using auth adaptor. (let me know if you want to enforce such requirement)
    But i think above solution solves your primary problem. Also please let me know if there are any issues in getting it work , i have given bare minimum which is required.

  • Recording and playing sound input from mic simultaneously in iphone/ipad

    I want to simultaneously record and play the sound from a mic in iphone. As thecricket commentory application.
    Please provide me a solution for this.
    Is this possible in iOs.

    This probably isn't going to sound very helpful, for which I apologise in advance, but I'm afraid it's the truth...
    The only way you stand any way of doing any of this is by using ASIO4ALL, which can aggregate different drivers from multiple devices. But I don't rate your chances too highly, I'm afraid - USB mics have long been the problem child of computer-based audio. On top of that, you are trying to get sounds in and out of a separate device at the same time - not only that, but it's a Creative Labs gamer's device and they are second only to USB mics in terms of the 'difficult' stakes - search this forum!
    A much, much better way to attempt to do this would be to use a sensible ASIO external device with sufficient inputs, and a mic that plugs into it, not a USB one. That way you could route the inputs and outputs appropriately, and use the device's monitoring so that you could monitor what you need to. I wouldn't attempt to do anything like this any other way, I'm afraid. Another approach (which can be made to work well) is to use an external mixer to do most of the work - often it's easier to set up the monitoring on these. You can get mixers with the appropriate interface built-in, and they don't cost a fortune either. Mackie and Behringer make suitable devices.

  • Record and play sound in SWF

    Hi List,
    I have developed standalone applications wherby i want the
    give the
    user an option of recording voice and then replaying the
    recorded
    sound. No need to save a file. Just record and listen.
    Is it possible to record and play sound in Flash swf-files
    without the Flash Communication Server?
    If not is there any third party component which can help me
    solve this purpose?

    No, don't think this is possible without Flash Media
    (formerly Communication) Server.
    Search these forums though. The question is asked pretty
    often, so maybe someone has offered a different answer.
    Cheers!

  • Record audio clip and play back it into media player

    how can i record voice clip using java application and play back it with media player.

    870902 wrote:
    how can i record voice clip using java application and play back it with media player.1) Record from "javasound://0" using a Processor / DataSink
    2) Play back the file from 1 using a Player

  • Recording and playing sound

    I am having a problem with sound in my program, it takes information from a TargetDataLine, put's it in a temporary file, then takes it back out of the temporary file and plays it using a SourceDataLine. currently, it does not play back the sound source code will follow in my next two posts.
    andrewjj20

    the play method:
    class Player implements Runnable {
    public Player() {
    public void run() {
    try {
    int bufferSize = (int)(format.getFrameSize()*rate*1);
    byte[] bytes = new byte[(int)bufferSize/12];
    lineOut.open(format,bufferSize);
    stopS = false;
    recording = false;
    playing = true;
    if (debug) {
    print("playing");
    status.setText("Playing");
    lineOut.start();
    while (!stopS) {
    if (in.available() != 0) {
         if(lineOut.available() != 0) {
         in.read(bytes);
         lineOut.write(bytes, 0, bytes.length);
    } else {
    stopS = true;
         resetGUI();
    lineOut.drain();
    lineOut.stop();
    lineOut.close();
    lineOut = null;
    stopS = false;
    recording = false;
    playing = false;
    status.setText("Done");
    if (debug) {
    print("Done");
    } catch (LineUnavailableException ex) {
    error("I can't acces the nessesary audio functions now");
    } catch (IOException ex) {
    error("Error communicating with the file.\nABORT!!! ABORT!!! ABORT!!!");
    }

  • Recording and Playing

    Hello
    I have a problem. I have one session of Audition recording and other session playing in the same PC. When I switch from one to another. both stop working.
    I can have 2 sessions opened, one recording and one playing at the same time and I can switch from one to another, with audition version 1.5, and both continue working.
    Thanks for your help.

    In Audio Hardware setup, take the check out of the box that says 'Release ASIO driver in background'. It's not an issue with 1.5 because this doesn't use ASIO, but every version beyond that does.

  • Audio Capture and Play - Problem. can u help?

    hello all
    currently i am working in a project for which i need to capture sound and play that using headphone. for this i have implemented two classes those r CaptureSound.java and PlaySound.java. most of the cases these classes r working fine but some time these do not work perfectly. when i capture i think the recording part works fine but when i am going to play that recorded file then its playing some noisy sound though this sound file is playing perfectly if i use any audio player and i have seen that the file properties r same as which is playing with my PlaySound.java. i have tried to find - what is wrong but i can't
    any one can help me for this problem?
    the classes r :
    import java.io.*;
    import javax.sound.sampled.*;
    import javax.sound.sampled.Port.*;
    public class CaptureSound {
         private AudioFormat audioFormat;
    private TargetDataLine targetDataLine;
    AudioFormat recordingFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 11025.0F, 16, 2, 4, 11025.0F, false);
         public CaptureSound(String filePath) {
              AudioFileFormat.Type fileType = null;
              File audioFile = null;
              fileType = AudioFileFormat.Type.WAVE;
              File createDirectory = new File("C:\\Capture\\test");
              if(!createDirectory.exists()) {
                   createDirectory.mkdirs();
              audioFile = new File(createDirectory + "\\1.wav");
              try {
                   audioFormat = recordingFormat;
              DataLine.Info dataLineInfo = new DataLine.Info(TargetDataLine.class, audioFormat);
              targetDataLine = (TargetDataLine) AudioSystem.getLine(dataLineInfo);
              targetDataLine.open(audioFormat);
              targetDataLine.start();
              AudioSystem.write(new AudioInputStream(targetDataLine), fileType, audioFile);
              } catch (Exception e) {
              e.printStackTrace();
              System.out.println("File Not Found");
    import java.io.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.io.*;
    import javax.sound.sampled.*;
    import java.net.URL;
    import java.awt.*;
    import java.net.URLConnection;
    public class PlaySound {
    private SourceDataLine sourcedataline;
    private AudioInputStream ais = null;
    private AudioFormat audioformat = null;
    private FloatControl gainControl;
    private InputStream inputStream = null;
    private boolean isPlayEnd = false;
         public PlaySound(String sourceFile) {
              try {
                   ais = AudioSystem.getAudioInputStream(new File("C:\\Capture\\test\1.wav"));
                   audioformat = getAudioFormat(ais);
         DataLine.Info datalineinfo = new DataLine.Info(SourceDataLine.class,audioformat);
              if (AudioSystem.isLineSupported(datalineinfo)) {
         sourcedataline = (SourceDataLine) AudioSystem.getLine(datalineinfo);
              sourcedataline.open(audioformat);
              //Copy data from the input stream to the output data line
              int framesizeinbytes = audioformat.getFrameSize();
              int bufferlengthinframes = sourcedataline.getBufferSize() / 8;
              int bufferlengthinbytes = bufferlengthinframes *framesizeinbytes;
              byte[] sounddata = new byte[bufferlengthinbytes];
              int numberofbytesread = 0;
              while ( (numberofbytesread = ais.read(sounddata, 0, sounddata.length)) != -1) {
                   if (!sourcedataline.isRunning()) {
                        sourcedataline.start();
              sourcedataline.write(sounddata, 0, numberofbytesread);
              isPlayEnd = false;
              isPlayEnd = true;
              } catch (LineUnavailableException lue) {
              } catch (IOException ioe) {
              } catch (NullPointerException npe) {
              } catch (ArrayIndexOutOfBoundsException npe) {
    } catch (UnsupportedAudioFileException use) {
         private AudioFormat getAudioFormat(AudioInputStream ais) throws
              UnsupportedAudioFileException, IOException {
         AudioFormat audioFormat = null;
         try {
              audioFormat = ais.getFormat();
         AudioFormat newformat = new AudioFormat(
         AudioFormat.Encoding.PCM_SIGNED,
         audioFormat.getSampleRate(),
         16, //audioFormat.getSampleSizeInBits()
         audioFormat.getChannels(),
         audioFormat.getChannels() * 2,
         audioFormat.getSampleRate(),
         false);
         AudioInputStream newStream = AudioSystem.getAudioInputStream(
              newformat, ais);
         audioFormat = newformat;
         ais = newStream;
              } catch (Exception e) {
              System.err.println("Exception: " + e.getMessage());
         return audioFormat;
    ///////////////////////////////////////////////////////////////////////////////////////////////////

    hello all
    i have captured sound with the format : AudioFormat recordingFormat = new AudioFormat(AudioFormat.Encoding.PCM_SIGNED, 11025.0F, 16, 2, 4, 11025.0F, false); now i want to play this file. for that i have created AudioInputStream and then i have created AudioFormat like:
    AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(new File("C://Capture//test.wav"));
    AudioFormat audioFormat = audioInputStream.getFormat();after this i have got the format like :
    bigEndian: boolean = true
    channels: int = 1
    frameRate: float = -1.0
    frameSize: int = -1
    sampleRate: float = 48000.0
    sampleSizeInBits: int = -1
    here i have found different file format and it can't play. why this is happening? can any one help for this?
    thanks
    bashar

  • Audio record and email, how do I?

    Sorry, I'm sure this is easy,, but not easy to find the answer...
    I would like to create/record an audio clip of myself and email it, I know there is a microphone on this laptop, but I don't know how to use it to record and email.
    thanks,
    J

    Well, you could record your voice using the PowerBook's internal microphone and the free application available at versiontracker called Audio Recorder. [Credit to Tuttle for turning me on to this app. a while back when I was in need of such a program.]
    I'm not sure, but I assume that you could then attach the file containing your recorded voice to an e-mail.
    If it doesn't work, post back....

  • Does Blackberry have Free Instant Voice Recording and Transcription?

    what i really would like is a portable device that can both record conversations and instantly transcribe them into a format that can be quickly and easily edited (the instant transcription doesn't have to be accurate) .. if the transcription can be edited by deleting or inserting more transcribed audio and if the editor permits audio playback of the transcribed file cued from places in the transcription, that would be a plus.
    it would be ideal if these features can exist in a phone with a small, physical keyboard, gps. a camera, wifi, mass data storage capability and expandable memory. i almost purchased the Torch 9810 sight unseen until i realized that what i really wanted was a voice recorder + transcriber (i already have other devices for gps, photos and internet so if these features come with, that's a bonus).
    does anyone know of any device/app like this on the market (i'm a complete noob when it comes to smartphones)?

    Rather that iMovie, you may want to check our Audacity.
    It's a free, open-source audio editor and recorder.
    You can easily save a recording as an MP3.
    http://audacity.sourceforge.net/
    Matt

  • Recording and playing back swfs

    I'd like to provide a users on my application the ability to record and playback what was on the swf. I can see how to capture from the camera but can't see any way to record the swf and save it as a swf (without each user buying a screen capture package).
    So I thought I might just record the basics (x,y,height,width,depth,alpha,rotation) of all the major MCs in the display list several times a second, save the details in an array and then allow the user to play the array back, creating and destroying MCs as necessary. This would be sufficient and quite efficient.
    The problem is when I loop through the display list looking for the 'object.name' of each mc I just get 'instance1, instance2' etc. I can't use that to extract the appropriate MC out of the library when I playback. How do I get a consistent name that refers to the item in the display name and the library item that I can use it to put it on stage?
    Also is there a way to create a list of all the MCs in the library?

    Just assign the objects names when you create them then use getChildByName to retreve them.
    f
    import flash.display.Sprite;
    import flash.display.DisplayObject;
    var container:Sprite = new Sprite();
    var sprite1:Sprite = new Sprite();
    sprite1.name = "sprite1";
    var sprite2:Sprite = new Sprite();
    sprite2.name = "sprite2";
    container.addChild(sprite1);
    container.addChild(sprite2);
    var target:DisplayObject = container.getChildByName("sprite1");
    trace(container.getChildIndex(target)); // 0

Maybe you are looking for