Subject:Extracting 30 seconds of audio
Posted by: JoeBellett
Date:3/14/2007 9:42:02 AM
I'm trying to find a script that will extract 30 seconds of audio from a file and save it as a new file whilst retaining the summary information from the original. The start point for the extraction would be 15 seconds, so you'd be extracting the audio between 15 and 45 seconds. I'm very new to the scripting, and cannot find a way of doing this easily. Does anyone have any ideas? Thanks |
Subject:RE: Extracting 30 seconds of audio
Reply by: _TJ
Date:3/18/2007 8:11:38 PM
As you may have already noticed, it's easy to do this if you don't care about summary data. if you do care, the easiest way is to work with the original file, and use SaveAs() to give it a new name. Most of the work is going to be the act of building a new filename. But since you didn't specify how that was supposed to work, I'm just going to hard-code it to e:\media\test.mp3 in my example. using System; using System.IO; using System.Windows.Forms; using SoundForge; public class EntryPoint { public void Begin(IScriptableApp app) { ISfFileHost file = app.CurrentFile; if (null == file) return; file.CropAudio(file.SecondsToPosition(15.0), file.SecondsToPosition(30.0)); file.SaveAs(@"e:\media\test.mp3", file.SaveFormat.Guid, 0, RenderOptions.RenderOnly | RenderOptions.Reopen); file.WaitForDoneOrCancel(); } 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; } //EntryPoint |
Subject:RE: Extracting 30 seconds of audio
Reply by: JoeBellett
Date:4/5/2007 12:37:58 AM
That's fantastic! I've played with this a bit and combined it with a crop and fade script in order to produce something that will take the 30 sec clip, fade it, and then save it. However, not being familiar enough with the language, I cannot find a way to replace the following code in the script with something that automatically defines the selection as the whole file rather than relying on the user selecting a portion of the active window: SfAudioSelection asel = wnd.Selection; if (asel.ccLength == 0) { DPF("No selection in the active window - quitting"); return "Choose a selection before running the script."; } I need something that defines 'SfAudioSelection asel' = the whole of the clip. Many thanks for your help. Message last edited on4/5/2007 11:26:00 AM byJoeBellett. |
Subject:RE: Extracting 30 seconds of audio
Reply by: _TJ
Date:4/6/2007 3:23:57 PM
to set the selection to the whole file, there are a variety of ways this will give you the selection, or the whole file if the selection has 0 length. SfAudioSelection asel = wnd.EditRegion this will always select the whole file SfAudioSelection asel = new SfAudioSelection(0, wnd.File.Length); or, if the asel has already been allocated in a previous operation, asel.Start = 0; asel.Length = wnd.File.Length; In many cases, you can get away with setting the length to -1 and the function that you call will interpret that as 'the remainder of the file". so asel.Start = 0; asel.Length = -1; file.DoEffect(..., asel, ...); will process the whole file. or there is a special case when allocating a new SfAudioSelection, if you pass an ISfFileHost as a parameter, it will set the selection to the whole file. like this: ISfFileHost file = app.CurrentFile; SfAudioSelection asel = new SfAudioSelection(fh); tj |
Subject:RE: Extracting 30 seconds of audio
Reply by: JoeBellett
Date:4/16/2007 10:11:10 AM
That's a great help. Thanks! Is there a way to run this script from Batch Convertor, or BC limited to SoundForge's built in effects etc? |
Subject:RE: Extracting 30 seconds of audio
Reply by: _TJ
Date:4/18/2007 3:33:17 PM
Sorry, Batch Converter Is limited to built in effects. |