Context Menu Option to Concatenate Audio Files


  1. Posts : 108
    Windows 7 and 10
       #1

    Context Menu Option to Concatenate Audio Files


    It seems like, in Windows 7 or maybe XP, I used to have a tool or tweak that would create a right-click option to immediately merge two audio (especially .wav and .mp3) files, producing a single output audio file that would contain both (or all of) the selected input files, one after the other. I don't remember what that old tool might have been called, and I am having a hard time finding anything like that in Win10.

    There are alternatives that will do the job, if you don't mind screwing around with a lot of settings and window moving, every time you want to join two audio files. Examples include Audacity, the command line, and various free or at least paid tools (e.g., Media Cope; those listed by Windows Report). But the extra clicks and settings are a killer if you need to perform such operations often.

    I've found JoinExt in Wayback (complete with source code, which I don't know how to modify). I don't think this was the tool I used previously, but it's got the right idea: select your (two or more) input .wavs, right-click, and a window opens to let you arrange the files in the desired order. Unfortunately, it seems to have been created in 2006. Apparently it worked in Win7, but in Win10 it seems to output only the first selected audio file.

    It seems like there ought to be a way to create a context menu entry that would simply run the copy /b input1.mp3 + input2.mp3 output.mp3 command. That would lack the option of rearranging the input order, but at least it would help in those cases where filename order suffices.
      My Computer


  2. Posts : 7,629
    Windows 10 Home 20H2
       #2

    raywood said:
    It seems like there ought to be a way to create a context menu entry that would simply run the copy /b input1.mp3 + input2.mp3 output.mp3 command.
    Do you mean something like this: Set Ethernet Connection as Metered or Unmetered in Windows 10
    If so, it can be done via a CMD script.
      My Computer


  3. Posts : 108
    Windows 7 and 10
    Thread Starter
       #3

    Matthew Wai said:
    Do you mean something like this: Set Ethernet Connection as Metered or Unmetered in Windows 10
    If so, it can be done via a CMD script.
    How?

    That would be the least helpful solution, but better than nothing.
      My Computer


  4. Posts : 7,629
    Windows 10 Home 20H2
       #4

    raywood said:
    How?
    For testing only:

    1. Download the attached "Testing.zip" and extract "Testing.cmd".
    2. Double-click on "Testing.cmd" to run it.
    3. On completion, you will see a new item "raywood" in your context menu.
    4. Click on "raywood", and the following command will be run.
    copy /b input1.mp3 + input2.mp3 output.mp3

    Actually, you can even run a script file rather than just a command.
    Context Menu Option to Concatenate Audio Files Attached Files
      My Computer


  5. Posts : 108
    Windows 7 and 10
    Thread Starter
       #5

    Thank you, Matthew. Even if (as it appears) you're really good at this, that looks like it must have taken some work.

    I didn't know it was possible to write .cmd files in plain text. Last time I tried to read one, which may have been a long time ago, I think I just saw gibberish. I guess the answer may be that this is just a batch file, but it uses the .cmd rather than the .bat extension.

    I know a little about batch scripting. Possibly just enough to be dangerous. So now, let me post the contents of your Testing.cmd and ask some questions. (This TenForums interface seems to use screwy line spacing -- like, in the composition box in which I am writing these words, it has inserted multiple blank lines between this paragraph and the preceding one -- and it wraps lines of code.)

    @echo off & title Add an item into the context menu.
    mode con cols=68 lines=16 & color 17
    :: ************************************************************************************/
    Set "Variable=0" & if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs"
    fsutil dirty query %systemdrive% >nul 2>&1 && goto :(Privileges_got)
    If "%1"=="%Variable%" (echo. &echo. Please right-click on the file and select &echo. "Run as administrator". &echo. Press any key to exit. &pause>nul 2>&1& exit)
    cmd /u /c echo Set UAC = CreateObject^("Shell.Application"^) : UAC.ShellExecute "%~0", "%Variable%", "", "runas", 1 > "%temp%\getadmin.vbs"&cscript //nologo "%temp%\getadmin.vbs" & exit
    :(Privileges_got)
    :: ************************************************************************************/
    cd /d "%~dp0"
    Set "Item=raywood" & Set "Command=copy /b input1.mp3 + input2.mp3 output.mp3"

    (REG Add "HKCR\Directory\Background\shell\%Item%\Command" /VE /D "%Command%" /F)
    If errorlevel 1 (echo.
    echo ====================================================================
    echo.
    echo The script has failed to perform the operations.
    echo Press any key to exit.
    echo.
    echo ====================================================================
    pause > nul & EXIT) else (echo.
    echo ====================================================================
    echo.
    echo The script has completed the operations.
    echo You will see "%Item%" in the context menu.
    echo Press any key to exit.
    echo.
    echo ====================================================================
    pause > nul & EXIT)



    If that's batch scripting, as I assume, it uses lots of things I didn't know existed.

    If I want the context menu item to be "Concatenate audio files," I assume I would substitute those words in place of "raywood" in your code.

    It appears the command summoned by that context menu item would be hardwired to merge two files named input1.mp3 and input2.mp3. It doesn't look like it would operate on any two randomly-selected-and-right-clicked files.

    It looks like the purpose of the script is to add the command, and its accompanying context menu entry, to the registry. I'm maybe more familiar with that, if only because it uses fewer lines. Can I achieve the same thing by manually adding that item to the registry, and then exporting and editing it for future use?
      My Computer


  6. Posts : 7,629
    Windows 10 Home 20H2
       #6

    raywood said:
    If I want the context menu item to be "Concatenate audio files," I assume I would substitute those words in place of "raywood" in your code.
    No problem. I can do the substitution.

    raywood said:
    It appears the command summoned by that context menu item would be hardwired to merge two files named input1.mp3 and input2.mp3. It doesn't look like it would operate on any two randomly-selected-and-right-clicked files.
    I can create a script that will open File Explorer, on which you can select files at random. However, if you want to select files by right-clicking on them, I will give it up because I am unable to do so.
    I have never run your command, so I want you to confirm the syntax.
    Take the following one for example.
    copy /b "D:\A folder\input1.mp3" + "D:\A folder\input2.mp3" "D:\A folder\output.mp3"
    Am I right in thinking that the first two files will be merged into output.mp3 if the file names and paths are correct?

    raywood said:
    Can I achieve the same thing by manually adding that item to the registry, and then exporting and editing it for future use?
    See whether you can understand this article: How to Add Any Application to the Windows Desktop Right-Click Menu
      My Computer


  7. Posts : 1,243
    W10-Pro 22H2
       #7

    I think I can help: I thought it would be easy, but it wasn't (for me), due to a number of wrinkles. I shall explain the what, and then the why.

    The what: My solution has 2 pieces: a context menu entry to 'join' two files, which calls stage 2: a batch file to do the joining. In my case the context menu item is
    Code:
    "HKCU\Software\Classes\VLC.mp3\shell\join\command\", "S:\test\join_mp3.bat %1"
    and the batch file contains this:
    Code:
    if exist temp.mp3 (
     copy /B %1+temp.mp3 out.mp3
     del temp.mp3
    ) else (
     copy %1 temp.mp3
    )
    Rather short, I know! You will have to tweak the reg entry to match the location of your batch file. The process should produce an output file with the two items joined in the order you selected them.

    How you get the context menu item into the registry is down to you - I use a .vbs file so I can easily undo it years later when I have forgotten where in the registry I put it.
    Code:
    Dim WSHShell
    Set WSHShell = WScript.CreateObject("WScripT.Shell")
    WSHShell.RegWrite "HKCU\Software\Classes\VLC.mp3\shell\join\command\", "S:\test\join_mp3.bat %1"
    'WSHShell.RegDelete "HKCU\Software\Classes\VLC.mp3\shell\join\command\"
    'WSHShell.RegDelete "HKCU\Software\Classes\VLC.mp3\shell\join\"
    but you could just edit the registry by hand, or create a .reg file. I shan't attach one, as your .mp3 entry may be different.

    The why: It is simple enough to select two files and rt-click on them, and Explorer picks the file names up and passes them to any command as parameters: %1, %2 etc - or rather it doesnt - it appears it processes the two files separately, by calling the command twice, and passing each file name as %1 - and actually passes the second selection first. This I found out the hard way. I could see no way to get these two passes to work together without an external control, hence the batch file. This creates a temporary file on the first pass (containing item #2), then on pass two it appends that to the end of item #1.

    It seems somewhat remarkable to me that such joined-up mp3 files work, but they certainly play in VLC.

    Reg entry: I did try to create an entry under .mp3, but it seems this did not take - I think because I have a default entry for .mp3 which points to VLC.mp3, and this takes precedence. Warning: you run the risk of messing up your media player file associations!

    There is rather a large caveat to this: it seems that the procedure may set up a race condition, so that sometimes the temp file gets deleted between being detected and being appended to, so the operation fails (I am not exactly sure what happens - if you can get this to work at all, you my want to try to fix this!).

    HTH, Martin
      My Computer


  8. Posts : 108
    Windows 7 and 10
    Thread Starter
       #8

    Yeah, that HTG article seems pretty straightforward. I hadn't ever thought of adding a batch script to the context menu. That may come in handy -- in this context and/or in others. Thanks for that link.

    It looks like I was mistaken in thinking that copy /b would reliably merge WAVs and MP3s (the audio filetypes that I am most likely to use). Various sources seem to indicate that, for the command line, I will have better results with FFmpeg or SoX.

    The choice of tool may depend on how I incorporate it into the context menu. It seems the sticking point here is, how could one send the names of two or more selected files to variables in a (FFmpeg or SoX) command or script invoked by a context menu entry? This seems to be the present shape of the question.
      My Computer


  9. Posts : 7,629
    Windows 10 Home 20H2
       #9

    raywood said:
    how could one send the names of two or more selected files to variables in a (FFmpeg or SoX) command or script invoked by a context menu entry?
    I can possibly do so via several CMD and VBScript files invoked by a context menu entry.

    raywood said:
    you're really good at this
    A guru really good at this can probably do so via a single file. So, I intend to sit back and wait for a guru to help you.
      My Computer


  10. Posts : 108
    Windows 7 and 10
    Thread Starter
       #10

    Well, Matthew, I think you've helped advance the cause. I appreciate it. If nothing else comes of it, at least I now have that way of adding an audio merging or editing tool to the context menu.

    Martin, thank you for that answer. That's a roll-up-the-sleeves response. I am only acknowledging now; I'm going to have to postpone a more intelligent reply until I can set aside some time and focus on this.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 19:12.
Find Us




Windows 10 Forums