Community Forums Archive

Go Back

Subject:Somewhat lengthy script assistance
Posted by: chap
Date:10/25/2013 7:21:24 PM

Hi there-
I'm working on Sound Forge version 10. I had a colleague that I had worked with years ago that processed files for me. unfortunately we have lost touch, so I know basically the input method but not how to build the script for the output.

basically what I have to do is record and process hundreds of lines of dialogue for a video game (favor for a friend). They have given me an excel sheet with the lines required. What I am doing is having the actor record basically one take per line, and we will do re-takes with any that aren't right.

For my friend we used to deliver him one WAV with metadata markers in between each take and a corresponding Excel sheet with the names that the files have to be.

He would then be able to turn around in rather short order the individual wav files, trimmed to 150ms of silence on either side.

I am thinking the script would involve "converting markers to regions", then saving each of the regions using the XML data from the name of the Excel sheet, applying auto trim to each event?

I am a Vegas Video editor with some knowledge of Sound Forge, this is my first delve into scripting, so any help would be appreciated.

thanks!
chap

Subject:RE: Somewhat lengthy script assistance
Reply by: roblesinge
Date:10/26/2013 11:20:46 AM

From what I understand, this should be pretty simple to script up. I want to make sure I understand what your goal is. I completely understand what you're trying to do here, as this is the exact kind of editing I do in my day job (we do voice prompts for telephone systems). We typically record everything into one big, raw file and then go in and pull out the individual phrases by hand. It seems that you want to automate that process.

So, you want a script that takes in a large wav file with a bunch of markers delineating individual phrase files. You need the script to parse those into individual files, trimmed to 150ms front and back and then named based on an excel sheet of some kind. Does that all sound correct?

Can you provide a small sample of the raw wav file with markers and the excel sheet?

Rob.

Subject:RE: Somewhat lengthy script assistance
Reply by: chap
Date:10/29/2013 11:35:36 AM

Sorry for the delayed reply. I always get involved with doing the project, then in order to deliver in time I just render everything one at a time out of Vegas. I have a few thousand more lines to do though, so building this script would indeed be ideal.

What you are asking is exactly right. My workflow would be as follows:

-Record all lines
-Edit best takes into single WAV file with markers separating each line.
-Export to individual WAV files with small amount of silence at each end.
-perhaps also normalize

You can download the files below, a small sample.
Download link
http://we.tl/GHos0sPHa7

In this example, column "B" would be the name that I would want each individual file to be at the end of the export, there would be 6 individual files all told.

Thank you very much for your help, I need to turn on the feature to alert me of replies!

Chap

Message last edited on10/29/2013 11:37:21 AM bychap.
Subject:RE: Somewhat lengthy script assistance
Reply by: roblesinge
Date:10/29/2013 3:49:35 PM

No worries, I figured you'd respond whenever you saw my reply. I haven't figured out how to get an e-mail or any kind of alert whenever someone posts in a thread I'm involved in. It's my main complaint with the Sony Forums.

Anyhow, I was able to code most of this up at lunch today. It needs some more debugging before it's ready for you. One thing I noticed is that you have 8 file names in the excel sheet, but only 6 markers (which would yield 5 files). I'm assuming that was just an oversight?

Also, out of curiosity, are there ever any files that are just silence? I know we have to build some silence files into our applications. Obviously silence files will be messed up during the auto trim/crop process of this script and will need to be dealt with separately. If this is something I need to build into the script, it will take a bit more work.

I should have more time to tinker with this tonight, and might have something for you tomorrow morning.

Rob.

Subject:RE: Somewhat lengthy script assistance
Reply by: chap
Date:10/29/2013 4:23:19 PM

Wow. Thanks so much, Rob! If there are any silence files they haven't notified me of them, these are all just straight edit and trims, perhaps it would be nice to be able to normalize or throw some sort of noise reduction on in future versions of the script. So, if they need any silence or noise samples I will just record that separately.

As for the markers I can put in as many as necessary, from what I recall I would simply put one marker in between every line that I wanted to trim out, and send the excel sheet, and my guy would just export the excel and put in some XML data. That would be it.

I knew I would get help here, but I didn't expect anyone to go and build the script for me. Is there anything I can do for you remuneration-wise, such as through PayPal?

Many many thanks!

Chapman

Message last edited on10/29/2013 4:24:49 PM bychap.
Subject:RE: Somewhat lengthy script assistance
Reply by: roblesinge
Date:10/30/2013 1:03:20 PM

I just sent you an e-mail via this site with links to the script with a video tutorial on my Dropbox. Let me know if the links don't come through and I'll figure out another way to get you the script.

Let me know if anything needs to be changed or fixed.

I'm also going to post the code here for posterity, in case anyone ever needs something similar and searches the forum.


using System;
using System.IO;
using System.Windows.Forms;
using SoundForge;
using System.Collections;
using System.Collections.Generic;

public class EntryPoint
{
public void Begin(IScriptableApp app)
{
String rawFilePath = String.Empty;
String txtFilePath = String.Empty;
String outputPath = String.Empty;
bool haveRawFilePath = false;
bool haveTxtFilePath = false;
bool haveOutputPath = false;

//Get all of our input and output information
OpenFileDialog opener = new OpenFileDialog();
opener.Filter = "WAV files (*.wav)|*.wav";
opener.RestoreDirectory = true;
opener.Title = "Choose the raw audio file.";

if ((rawFilePath = PathGetter(opener)) != "UserCancelled")
haveRawFilePath = true;

opener = new OpenFileDialog();
opener.Filter = "TXT Files (*.txt)|*.txt";
opener.RestoreDirectory = true;
opener.Title = "Choose the Text file.";

if (haveRawFilePath)
{
if ((txtFilePath = PathGetter(opener)) != "UserCancelled")
haveTxtFilePath = true;
}

if (haveRawFilePath && haveTxtFilePath)
{
outputPath = SfHelpers.ChooseDirectory("Choose the OUTPUT folder.", null);
DPF(outputPath);
if (outputPath != null)
haveOutputPath = true;
}


//Pull in and store our output file names from the text file
if (haveRawFilePath && haveTxtFilePath && haveOutputPath)
{
List<String> fileNameList = new List<String>();

try
{
using (FileStream fs = File.OpenRead(txtFilePath))
{
using (StreamReader sr = new StreamReader(fs))
{
String line = String.Empty;
while ((line = sr.ReadLine()) != null)
{
DPF(line);
fileNameList.Add(line.Trim());
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("File could not be read. Original Error: " + ex.Message);
//return;
}

//Start working with our audio files

//Create an AutoTrim Crop setup to trim all silence from edges of our file.
Fields_AutoTrimCrop cropSetup = new Fields_AutoTrimCrop();
cropSetup.EndThreshold = -50.0;
cropSetup.Function = Fields_AutoTrimCrop.CropFunction.KeepEdges;
cropSetup.InTime = 20; //20 ms of fade in when thresh is detected
cropSetup.OutTime = 20; //20 ms of fade out when thresh is detected
cropSetup.StartThreshold = -50.0;

ISfGenericEffect autoTC = app.FindEffect("Process.AutoTrimCrop");
ISfGenericPreset preset = autoTC.GetPreset("");
cropSetup.ToPreset(preset);

ISfFileHost rawFile = app.OpenFile(rawFilePath, true, true);

//create a save format for our output files based on the raw input file
SfWaveFormat format = new SfWaveFormat(rawFile.SampleType, rawFile.SampleRate, rawFile.Channels);
SfAudioMarkerList markerList = new SfAudioMarkerList(rawFile);

for (int x = 0; x < markerList.Count - 1; x++) //There has to be a marker at the end of the last phrase for this to work properly.
{
SfAudioSelection asel = new SfAudioSelection(markerList[x].Start, (markerList[x + 1].Start - markerList[x].Start));

ISfFileHost outFile = app.NewFile(format, true);
outFile.OverwriteAudio(0, 0, rawFile, asel);

outFile.DoEffect("Process.AutoTrimCrop", preset, new SfAudioSelection(outFile), EffectOptions.EffectOnly);
outFile.InsertSilence(outFile.Length, outFile.SecondsToPosition(.150)); //Silence added here. Change the number if you want different silence.

DPF(fileNameList[x]);

//String outFileName = String.Format("{0}\\{1}.wav", outputPath, fileNameList[x]);
String outFileName = Path.Combine(outputPath, fileNameList[x]);
outFileName = outFileName + ".wav";
DPF(outFileName);
outFile.SaveAs(outFileName, ".wav", "Default Template", RenderOptions.WaitForDoneOrCancel);
outFile.Close(CloseOptions.SaveChanges);
}

rawFile.Close(CloseOptions.DiscardChanges);
}
else
return;
}

public String PathGetter(OpenFileDialog open)
{
String path = String.Empty;

DialogResult result = open.ShowDialog();

if (result == DialogResult.OK)
{
try
{
path = open.FileName;
DPF(path);
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original Error: " + ex.Message);
}
}
else if (result == DialogResult.Cancel)
{
path = "UserCancelled";
}

return path;
}

public void FromSoundForge(IScriptableApp app)
{
ForgeApp = app; //execution begins here
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
Begin(app);
app.SetStatusText(String.Format("Script '{0}' is done.", Script.Name));
}
public static IScriptableApp ForgeApp = null;
public static void DPF(string sz) { ForgeApp.OutputText(sz); }
public static void DPF(string fmt, params object[] args) { ForgeApp.OutputText(String.Format(fmt, args)); }
} //EntryPoint


Rob.

Subject:RE: Somewhat lengthy script assistance
Reply by: chap
Date:11/14/2013 11:32:08 PM

ROBELSINGE-
What can I say? Your script was beautiful, and flawless. Your video which went with it was incredibly helpful, and so far above and beyond what I expected with my post in this forum. You have saved me countless hours of work and what's more, you brought the budget back under control, as we were having to cut lines and chapters of work because of the amount of processing.

In short, you are a God Among Men, and THANK YOU THANK YOU THANK YOU for your selfless time and effort.

Karmically, my friend is starting a video games company, and I will not forget you the next time someone is looking for an audio editor of any capacity.

Out of curiousity, what city are you in? I live in Los Angeles and have friends getting bigger and bigger projects every day....

best,
matt chapman

Go Back