Community Forums Archive

Go Back

Subject:need help using time stretch from script
Posted by: JimB15122
Date:11/8/2012 2:56:41 PM

I am trying to write a sf 10 script to time stretch/shrink a file. Ive been at it for several days, and can not get it to work

Background/Requirements:
I need a simple command utility (non gui, non interactive) that accepts a wav file name, and shrink/stretch factor, and applies the change to the specified file. (then ends)
This would be launched from another controlling program, as files are discovered to be processed. (no gui, no user interaction, and ideally no preliminary preset setup to soundforge itself) - eg: it should be possible to specify any shrink/stretch factor within the supported range. .5 to 5

Here is what I came up with: (does not work - please help)

1) the main program launches SF as follows:
"C:\Program Files\Sony\Sound Forge Pro 10.0\Forge100.exe" -SCRIPTARGS:"WAV=C:\some.wav&SPD=80" -SCRIPT:"C:\shrink.cs" -EXIT

the WAV arg specifies the file to process.
the SPD arg in an integer PERCENTAGE. eg 80 will be converted to .8 in the script


2) shrink.cs follows: - The file is not changed!!
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 strWavFile = GETARG("WAV","WAV file name argument is missing");
int iSpeed = GETARG( "SPD", -1 );

ISfFileHost hostWavFile = app.OpenFile(strWavFile, false, false); // not read only, no window

Fields_TimeStretch tsArgs = new Fields_TimeStretch();
tsArgs.Mode = Fields_TimeStretch.StretchMode.Speech2;
tsArgs.Percent = iSpeed / 100.0;

ISfGenericEffect tsEffect = app.FindEffect("Sony Time Stretch");
SfGenericPreset tsPreset = new SfGenericPreset( tsEffect.GetPreset("") );

tsArgs.ToPreset( tsPreset );

hostWavFile.DoEffect( tsEffect.Name, tsPreset, new SfAudioSelection(0,-1), EffectOptions.EffectOnly | EffectOptions.WaitForDoneOrCancel );

hostWavFile.Save( SaveOptions.WaitForDoneOrCancel );
DPF("Saved {0}", strWavFile);
hostWavFile.Close( CloseOptions.SaveChanges );
}

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)); }
public static string GETARG(string k, string d) { string val = Script.Args.ValueOf(k); if (val == null || val.Length == 0) val = d; return val; }
public static int GETARG(string k, int d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsInt(k); }
public static bool GETARG(string k, bool d) { string s = Script.Args.ValueOf(k); if (s == null || s.Length == 0) return d; else return Script.Args.AsBool(k); }
} //EntryPoint

======================================
i verified that the ARGS are being passed correctly into the script, etc.
This does not work from the scripting window either.
can someone please help?
is there an example of doing a time stretch from a script somewhere?

Message last edited on11/8/2012 2:59:43 PM byJimB15122.
Subject:RE: need help using time stretch from script
Reply by: roblesinge
Date:11/9/2012 8:56:38 AM

I only had a second to glance at this yesterday, but it all looked okay from a SF perspective. I should have more time to play with it over the weekend. I'm going to first try and get it working in SF and then hand it to you to get it working from the command line.

Rob.

Subject:RE: need help using time stretch from script
Reply by: JimB15122
Date:11/9/2012 9:15:31 AM

Thanks so much Rob.
I forgot to mention that the wav files to be processed are typically recorded in 22K or 16k, 16 bit, mono. They are normal human speech (no singing), and are usually less than 5 seconds long. Shrinking these from the gui works fine.
The only concern is audio quality; conversion quickness does not matter.
The shrink ratios will range from .5 to .8

Jim B.

Subject:RE: need help using time stretch from script
Reply by: roblesinge
Date:11/15/2012 10:31:28 PM

I've been playing with this off and on for a few days now. The only thing I can figure is this can't be done without the presets already in place. The Percent property appears to be the length of the selection and not the percentage by which you want to stretch the audio (which is the worst bit of naming I've ever come across if that is the case). The protected "dPercent" property, which it doesn't seem can be accessed, is what actually controls the amount of stretch applied. I'm not sure why it would be coded like that, but it could be just that it's above my pay-grade as a hack scripting programmer. It seems ridiculous that you wouldn't have control over the percentage by which the stretch happens. It certainly limits the functionality of the effect from a scripting perspective.

Unfortunately, it would seem that you would have to create a preset for EVERY percentage of stretch available and then call a preset based on the ARG passed in, which is ludicrous.

Perhaps someone with more experience scripting the TimeStretch effect has more info, but I wouldn't hold my breath. This particular part of the forum is pretty barren these days, which is sad.

Rob.

Go Back