[UCCx] Change volume of an audio file (java code)

Hello guys,
Thanks to the many examples I compiled on the subject, I was able to create a script that mixes 2 audio wav files into a 3rd one. Basically the goal is to mix a first audio file containing some speech with a second one containing some music, these files being encoded identically (8 bits, 8KHz, mono wav files). The resulting file must be encoded in the same format than the initial ones.
The mixing operation is performed thanks to the MixingAudioInputStream library found online (it can be found here).
It is not the most beautiful Java code (I am no developer), but it works:
Document doc1 = (Document) promptFlux1;
Document doc2 = (Document) promptFlux2;
Document docFinal = (Document) promptFinal;
javax.sound.sampled.AudioFormat formatAudio = null;
java.util.List audioInputStreamList = new java.util.ArrayList();
javax.sound.sampled.AudioInputStream ais1 = null;
javax.sound.sampled.AudioInputStream ais2 = null;
javax.sound.sampled.AudioInputStream aisTemp = null;
javax.sound.sampled.AudioFileFormat formatFichierAudio = javax.sound.sampled.AudioSystem.getAudioFileFormat(new java.io.BufferedInputStream(doc1.getInputStream()));
java.io.File fichierTemp = java.io.File.createTempFile("wav", "tmp");
ais1 = javax.sound.sampled.AudioSystem.getAudioInputStream(doc1.getInputStream());
formatAudio = ais1.getFormat();
aisTemp = javax.sound.sampled.AudioSystem.getAudioInputStream(doc2.getInputStream());
byte[] bufferTemp = new byte[(int)ais1.getFrameLength()];
int nbOctetsLus = aisTemp.read(bufferTemp, 0, bufferTemp.length);
java.io.ByteArrayInputStream baisTemp = new java.io.ByteArrayInputStream(bufferTemp);
ais2 = new javax.sound.sampled.AudioInputStream(baisTemp, formatAudio, bufferTemp.length/formatAudio.getFrameSize());
audioInputStreamList.add(ais1);
audioInputStreamList.add(ais2);
MixingAudioInputStream mixer = new MixingAudioInputStream(formatAudio, audioInputStreamList);
javax.sound.sampled.AudioSystem.write(mixer, formatFichierAudio.getType(), fichierTemp);
return fichierTemp;
The only downside to this is that the music can be a little loud comparing to the speech. So I am now trying to use the AmplitudeAudioInputStream library to adjust the volume of the second file (it can be found here).
Here are the additional lines I wrote to do this:
ais2 = new javax.sound.sampled.AudioInputStream(baisTemp, formatAudio, bufferTemp.length/formatAudio.getFrameSize());
org.tritonus.dsp.ais.AmplitudeAudioInputStream amplifiedAudioInputStream = new org.tritonus.dsp.ais.AmplitudeAudioInputStream(ais2, formatAudio);
amplifiedAudioInputStream.setAmplitudeLinear(0.2F);
audioInputStreamList.add(ais1);
audioInputStreamList.add(amplifiedAudioInputStream);
MixingAudioInputStream mixer = new MixingAudioInputStream(formatAudio, audioInputStreamList);
javax.sound.sampled.AudioSystem.write(mixer, formatFichierAudio.getType(), fichierTemp);
return fichierTemp;
The problem is I always get the following exception when executing the code:
could not write audio file: file type not supported: WAVE; nested exception is: java.lang.IllegalArgumentException: could not write audio file: file type not supported: WAVE (line 30, col:2)
The error is on the last line (the write method), but after many hours of tests and research I cannot understand why this is not working... so I have added some "debugging" information to the code:
System.out.println("file1 audio file format: " + formatFichierAudio.toString());
System.out.println("file1 file format: " + ais1.getFormat().toString());
System.out.println("file2 file format: " + ais2.getFormat().toString());
System.out.println("AIS with modified volume file format: " + amplifiedAudioInputStream.getFormat().toString());
System.out.println("Mixed AIS (final) file format: " + mixer.getFormat().toString());
AudioFileFormat.Type[] typesDeFichiers = AudioSystem.getAudioFileTypes(mixer);
for (int i = 0; i < typesDeFichiers.length ; i++) {
System.out.println("Mixed AIS (final) #" + i + " supported file format: " + typesDeFichiers[i].toString());
System.out.println("Is WAVE format supported by Mixed AIS (final): " + AudioSystem.isFileTypeSupported(AudioFileFormat.Type.WAVE, mixer));
System.out.println("Destination file format: " + (AudioSystem.getAudioFileFormat((java.io.File)f)).toString());
AudioInputStream aisFinal = AudioSystem.getAudioInputStream(f);
System.out.println("Is WAVE format supported by destination file: " + AudioSystem.isFileTypeSupported(AudioFileFormat.Type.WAVE, aisFinal));
try {
// Ecriture du flux résultant dans un fichier
javax.sound.sampled.AudioSystem.write(mixer, formatFichierAudio.getType(), fichierTemp);
return fichierTemp;
catch (Exception e) {
System.err.println("Caught Exception: " + e.getMessage());
Which gives the following result during execution:
file1 audio file format: WAVE (.wav) file, byte length: 146964, data format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, , frame length: 146906
file1 file format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame,
file2 file format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame,
AIS with modified volume file format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame,
Mixed AIS (final) file format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame,
Mixed AIS (final) #1 supported file format: WAVE
Mixed AIS (final) #2 supported file format: AU
Mixed AIS (final) #3 supported file format: AIFF
Is WAVE format supported by Mixed AIS (final): true
Destination file format: WAVE (.wav) file, byte length: 146952, data format: ULAW 8000.0 Hz, 8 bit, mono, 1 bytes/frame, , frame length: 146906
Is WAVE format supported by destination file: true
So everything tends to show that the format should be supported and the mixed AIS should be written to the file... but I still get the error.
I am really confused here, if someone could help it would be great.
Thanks in advance!
PS: I have attached print screens of the actual script, without the "volume adjustment" code.

Hi,
well I started writing a similar solution but it did not work either so I just put it on hold.
I also tried to get hold of the streaming "device" abstraction of UCCX to adjust the volume while "playing" but that was a dead end, too, unfortunately.
Sorry about my previous comment on your StackOverflow post, that time I thought it was kind of out of context but I believe you only wanted to ask about this issue on all available forums.
G.

Similar Messages

  • Change the volume of one audio file played in icm script

    Hello,
    Using the play external script element to simply play queue music (recorded as 10 minutes long), is there a way to adjust the volume of the audio being played within the script without having to re-record that specific audio file?
    95% of our static audio is recorded fine and plays at the appropriate volume, but we have new queue music coming in all the time (with sales info, annoncements, etc.) that is different in volume from time to time and it would be nice to have an adjustment filter for playing that specific audio file and then adjust back to the default (if needed) afterward.
    This would be much easier than asking our vendor to re-record over and over again until tested right.
    Anything possible with this? Or would there be something on CVP that could control volume for one specific audio file?
    Thanks for any info,
    Greg

    Even if CVP could control the volume on individual files (It can't, as far as I know), you're better off normalizing the file in Audacity as David mentioned. Having some server modify things on the fly is just wasting resources, why not adjust the file? Audacity is free and open source.
    We record our voice prompts using a Unity Connections Voicemail box... Not the cleanest solution, but it works well for us as we have small global contact centers all in different regions, with different voices for each center. I make a habit of running all of my files through Audacity before putting them on media servers - otherwise I would potentially have prompts recorded at different times having different volumes depending on how "the voice" and Unity were doing that day, not to mention all the pops and clicks from using a sub-optimal recording solution.  Normalize and the Envelope Tool are my best friends.
    -Jameson

  • Adapter module to read excel file -java code required for PI 7.1

    Hi PI experts,
    I am working on PI 7.1 SP 08.
    I am trying to develope an adapter module to read excel file
    http://wiki.sdn.sap.com/wiki/display/ABAP/AdapterModuleToReadExcelFilewithMultipleRowsandMultiple+Columns
    but here in this wiki , given java code is for pi 7.0 and it is using jar file from PI 7.0
    I tried with using corresponding PI 7.1 files
    com.sap.aii.af.lib.mod.jar:
    sap.comtcloggingjavaimpl.jar:
    com.sap.aii.af.svc_api.jar:
    com.sap.aii.af.cpa.svc_api.jar:
    com.sap.aii.af.ms.ifc_api.jar:
    jave program is not throwing any error in NWDS but After deploying file on server.
    i am getting this errot in communication channel
    2009-12-15 15:47:08 Information AO: Now calling the Convert Method to convert Excel to XML.
    2009-12-15 15:47:08 Error MP: exception caught with cause javax.ejb.TransactionRolledbackLocalException: nested exception is: java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: Bad version number in .class file; nested exception is: javax.ejb.EJBException: nested exception is: java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: Bad version number in .class file; nested exception is: javax.ejb.EJBTransactionRolledbackException: nested exception is: java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: Bad version number in .class file; nested exception is: javax.ejb.EJBException: nested exception is: java.lang.RuntimeException: java.lang.UnsupportedClassVersionError: Bad version number in .class file
    since i am not a JAVA expert so i am unable to resolve this error
    if some one has already deployed this module for PI 7.1, then please provide me java code for PI 7.1
    Thanks
    sandeep sharma

    hi,
    please try this:
    obj = inputModuleData.getPrincipalData();
    msg = (Message) obj;
    amk = new MessageKey(msg.getMessageId(),msg.getMessageDirection());
    XMLPayload xpld = msg.getDocument();
    Workbook wb = Workbook.getWorkbook((InputStream) xpld.getInputStream());
    xmldata ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n"+ "<ns0:"msgType" ""xmlns:ns0=\""nameSpace+"\">";
    Cell[] cells ;
    Cell[] cellNames ;
    cellNames = wb.getSheet(0).getRow(0);
    for(int j=1;j<wb.getSheet(0).getRows();j++)
    xmldata = xmldata+"<Record>";
    cells = wb.getSheet(0).getRow(j);
    for(int i=0;i<wb.getSheet(0).getColumns();i++)
    xmldata = xmldata"<"cellNames<i>.getContents()">"cells<i>.getContents()"</"cellNames<i>.getContents()+">";
    xmldata = xmldata+"</Record>";
    xmldata = xmldata"</ns0:"msgType+">"; 
    wb.close();
    byte byt[] = xmldata.getBytes();
    xpld.setContent(byt);
    inputModuleData.setPrincipalData(msg);
    Thanks,
    Mayank

  • Change the Summary Attribute Value through Java code

    Hi ,
    I am working on a requirement where I need to set the Attribute value on the final Summary Screen through Java Code.
    Code :
            InterviewUserData data = new InterviewUserData();
            InterviewEntityInstance globalInstance = data.getGlobalInstance();
            globalInstance.setValue("Name", value_to_set);
    On completion of the interview session Name is displaying as NULL.
    I need to set NAME = value_to_set and display it on the final summary screen.
    Any help on this will be appreciated.
    Regards

    The InterviewUserData object is effectively a change set, to apply this to a session you use the InterviewSession.submit(InterviewUserData) method. You don't say how you are invoking this code but if it's inside an event Interview Engine handler the InterviewSession object should be accessible.
    Regards
    Ian

  • How do I allow meeting participants to control the volume of an audio file in Adobe Connect 9?

    The feature of changing the audio volume as a participant in an Adobe Connect meeting seems to have gone away in version 9.
    It is missing on both audio and video files, and I am currently losing paying customers because the volume is either too low or too high.
    How do I give my users audio volume control again?

    Select all of your audio, go to the Modify > Audio > Apply Audio Normalization. It will bring all clips in each track to be the same level. Then, later, you can do your final mix much easier.
    Or go to Window > Arrange > Audio Mixing and you'll have an on-screen mixing board to work with. There's a speaker icon in the top right, green keyframing is on while you mix in realtime during playback, gray, keyframing is off.
    But use the first method first, for sure. Open the audio mixer after that, you'll save yourself a ton of work and time.
    Message was edited by: BenB

  • Change volume for whole audio track

    Hi gang,
    I feel like I am missing something obvious ...
    I have a stereo background noise that recurs across my sequence. It is pasted into audio tracks A13 and A14 with crossfades between each occurrence. I want to fade the volume of all of them at the same time (i.e. all of the audio clips pasted into A13 and A14). If I select all of them by dragging a box using the mouse, it does not set the volume for all of the clips, only the last
    How do you change the volume for a whole track?
    Cheers!

    whats more, had you already manually adjusted some clips but not others and then wanted to adjust all the clips to the same level regardless of your previous adjustment then there's really no need to remove levels attributes, or redit etc etc ... you just follow the same steps posted above, choosing "Absolute" as the Gain adjustment - all clips regardless of previous levels will be set to the absolute level you specify.

  • Changing from MPEG-4 audio file (protected) to MP3 audio format?

    i dont know if its a stupid question, if its possible or if they are the same thing.
    its just to tranfer songs to my phone they need to be in mp3 format.
    any info...even to say its not possible would be good.
    legal too.
    sami.

    You can burn the protected file to an audio CD which you can then use as you would any other audio CD.

  • Logic changing the names of audio files when I drag and drop into arrange

    i am dropping some 44.1/24 bit files into logic and for some reason out of nowhere the names of the files are changed. it removes digits i have entered in the file for identification purposes, so i am no longer sure what they are, and seems to be replacing it with "#". could it have something to do with import settings? i have not changed any...

    This happens because until recently Logic didn't handle long filenames very well.
    Long filename support was added in Logic 9.1.x so I recommend upgrading to that version - or using shorter file/pathnames.
    The #7875 bit appended to the name is the number of the disk block the file is stored at...

  • Waveburner changing the pitch of audio files

    Maybe it wasn't a good idea to go ahead and update right at the end of a project (i know i know), but the new 1.5 version of WB is pitching every song up about a whole step.
    I checked the preferences and the manual (both of which are VERY sparce), re-bounced all of the original mixes in real time again and converted them all to 44.1/16 (the previous files used in this project were 48khz/24bit). Still the pitched upedness.
    I thought it might be a sample rate issue but it does the same chipmonk thingno matter what files I put in at whatever rate they might be in. Starting a new project from scratch made no difference either.
    Someone smarter than me please tell me I'm just overlooking something obvious.

    This happens because until recently Logic didn't handle long filenames very well.
    Long filename support was added in Logic 9.1.x so I recommend upgrading to that version - or using shorter file/pathnames.
    The #7875 bit appended to the name is the number of the disk block the file is stored at...

  • Using The Same Audio Files On Multiple Platforms

    When I import new audio into logic - often it will say that is creating wave forms for the display.
    Q: I notice that the audio files on disk do not show an altered modified date - so where are these wave form displays being saved - on the audio file or inside the logic song?
    Q: I am interested in possibly going back and forth between logic and Pro tools LE - and at different times using the same audio files for both platforms. Assuming I am not doing any destructive editing - is it OK to use the same set of files for both platforms - or do I need to make duplicates (I'd rather not)? Also, how does this wave form display get dealt with by going back and forth between the two platforms?

    A: the waveform overlays are stored in separate,
    temporary files - *.ovm files or something, but my
    memory is fuzzy on that for now. The original audio
    files are not modified in any way.
    Hmmm... I've wondererd about this, too, and as best I can tell, Logic DOES modify the original files.
    I just imported some stereo interleaved AIF files into a project (with "copy external audio files to project folder" disabled), and I couldn't see any evidence of waveform creation--a disk search by date revealed nothing looking like waveform overviews, and there were no modifications to the AIF file dates.
    So... the next time I imported some AIF files, I checked the file sizes before the import...
    Sure enough, the files got bigger by about 100K after being imported into a Logic session, even though the file's timestamps were not changed.
    Looks like maybe Logic does write the waveforms into the files themselves ?
    On a related note, the manual suggests that it's possible to change the "copy external audio files to project folder" setting after creating a project, but I haven't found this anywhere other than File->New... anyone know ?
    Thanks!
    James
    [email protected]
    Dual 1.25 G4   Mac OS X (10.4.8)  

  • Sound VIs with audio files

    I've been stuck with this VI that's supposed let the user set the frecuency and volume of an audio file, and play it.
    I managed to get the frecuency part working with Play Waveform, but that doesn't let the volume be modified (or the playback to be stopped before it finishes, as far as I know). So I tried writing it directly into the sound card with the other Sound VIs, but I've only managed distortion with continuous samples, or silence and crashes with finite ones, which are what I understand I should be using. 
    I've been trying to figure this out for hours, and I think most of my problems come from my lack of understanding of how the Sound VIs work, despite reading their help and support pages several times.
    I've attached my latest VI. The playback doesn't work at all and it may crash your computer if it's anything like mine, but as long as you don't try to play anything it should be safe.
    Attachments:
    Frecuency and Volume modification.vi ‏48 KB

    Hi. I'm sorry for the late reply.
    In the end, I managed to get the VI working by mofifying the program entirely. I'm still no sure what kept causing the crashes, but I'll try to figure it out at a later time using your advice. 
    I'm very thankful for your reply, it made me realize there's a lot of tools in LabView that I've been ignoring because I never received proper instruction on the program. 

  • Can I change the Jar contents trough Java code ?

    It may seems a little bit wierd, but it could solve a lot of acessibility problms....
    Can I change/set the jar contents using java code ?
    My real problem: I'm creating a EDI Client and using a XML file as configuration file. It's running well but this XML is much exposed to unauthorized users....
    Can I set a value in this XML file if it is inside a jar file ??

    you can look at class JarOutputStream . You could also use class RunTime to just create a new jar with the proper files via the normal jar command.

  • Java code for Compressing files in UNIX

    Hi ,
    i am trying to compress files in unix but not seeing any change in size of packed file .any code please help.

    Hi ,
    i am trying to compress files in unix but not seeing
    any change in size of packed file .any code please
    help.Does this question have anything to with Java whatsoever? If so how? And what types of files are you attempting to compress? If you are trying to compress a compress format the size difference will be... small if not actually worse then the originial.

  • Changing Volume Levels

    1.) When raising or lowering the volume of an audio file, is there a way to know what -21 db is? Is this a fixed form of measurement, or is it based on the audio levels of the original file?
    2.) Is there a way to visually see when noise is being introduced when the "Level" is raised in the Viewer?
    3.) When wanting to raise volume, when is it better to raise the Levels, vs. Copying and pasting the track to increase the volume? Which situations work best for what?
    Thanks!!!

    1.) Are you asking about output level or gain level? By default, all FW captured audio comes into FCP with a gain level of 0db, regardless of it's output level. Gain level (the amount of adjustment from the default setting) can be seen in the Viewer window. Output level can be seen on the meters.
    2.) Not unless you're really, really good a reading waveforms.
    3.) Both methods achieve the same thing; raising the output level (volume). Of course, both methods also raise the noise floor. Duplicating the clip on the Timeline is much like assigning an analog mixer's channel to an additional bus.
    You can also use the Dynamic Processor filter to raise the level beyond FCP's +12db gain limit.
    -DH

  • Handling events from native objects in Java code - Code from Sachin Agrawal

    Hi All,
    I�ve been studing this example in http://www.ibm.com/developerworks/java/library/j-jniobs/ , so I find it so interesting to be used on programs, but I'm just a starter programmer when we talk about JNI.
    I hope that some good soul will tell me how I use it in java.
    Let me explain better.
    In this example, a main.exe it's the reponsible to call the entire program, java and C. I want to use this code, but, In java. Or better, I wanna know what I have to change, to call it from my Java code...
    for example, I've tryed this:
    package events;
    import javax.swing.JFrame;
    public class MouseDownListener extends JFrame implements IJMouseDownListener {
         EventSourceProxy _proxy;
         IJMouseDownListener _listener;
         public MouseDownListener(int handleEventSource) {
              _proxy = EventSourceProxy.get(handleEventSource);
              if (null == _proxy) {
                   return;
              _listener = new IJMouseDownListener() {
                   public void onMouseDown(int hPos, int vPos) {
                        System.out.println("In MouseDownListener.onMouseDown");
                        System.out.println("     X = " + String.valueOf(hPos));
                        System.out.println("     Y = " + String.valueOf(vPos));
              _proxy.addMouseDownListener(_listener);
         public void release() {
              _proxy.removeMouseDownListener(_listener);
              _listener = null;
              _proxy = null;
             public void onMouseDown(int x, int y){
            System.out.println(x + "-" +y );
         public static void main(String[] argv) {
              MouseDownListener listener = new MouseDownListener(0);
                    listener.setVisible(true);
    }but doesn�t work.
    Thanks for your help!

    Jschell Hello,
    I really think that I was not very clear in my question.
    Sorry about my very bad English.
    In the example linked, there is a file main.cpp that starts the program:
    // Defines the entry point
    #include "EventSource.h"
    #include "MouseDownListener.h"
    #include "Jvm.h"
    #include <process.h>
    #include <windows.h>
    void __cdecl ThreadMain(void * pSource)
         ((CEventSource *)pSource)->fireMouseDownEvent(50, 100);
         CJvm::DetachThread();
    int main(int argc, char* argv[])
         CEventSource eventSource;
         CMouseDownListener listener;
         eventSource.addMouseDownListener(&listener);
         CJvm::CreateJVM(argc-1, &argv[1]);
         jobject jobj = CJvm::CreateJavaObject("events/MouseDownListener", (int)(IEventSource *)&eventSource);
         _beginthread(ThreadMain, 0, &eventSource);
         Sleep(2000);
         CJvm::ReleaseJObject(jobj);
         CJvm::DestroyJVM();
         return 0;
    }And the command line to execute all the thing is
    main.exe "-Djava.class.path=.\\java\\bin"
    "-Djava.library.path=.\\cpp\\listener\\Debug"and the result in a dos prompt is:
    In CMouseDownListener::onMouseDown
    X = 50
    Y = 100
    In MouseDownListener.onMouseDown
    X = 50
    Y = 100
    According to the example, this code main.cpp, calls the Java classes too:
    EventSourceProxy.java, IJMouseDownListener.java, MouseDownListener.java.
    But, I want to modify it so that I can start my program directly from within Java in a way that I start the program with something like
    "Main java," plus the required parameters, and can thus manipulate the results obtained through the java.
    In short, I wanted to translate the main.cpp for Java, so I have a main class in Java that start the program, call the listener.dll through JNI, take the position of the mouse, and return to my program in Java.
    If you or someone else can help me,'ll be very grateful.
    Tkd,
    Dino

Maybe you are looking for