Community Forums Archive

Go Back

Subject:Region/Marker info to XML for use in Flash
Posted by: sound-kobo
Date:1/6/2007 11:12:56 PM

Greetings.

I'm creating English learning materials using Flash. Sound Forge is used for recording sentences, marking word boundaries into regions, extracting regions into separate files, etc. Problem is the number of files and the time it takes to manually save each one and then script in Flash.

Is it possible to completely automate the process (minus making the regions)??

I'd really like to be able to name the regions something like

Region01 = "01, word01, unstressed"
Region02 = "02, word02, stressed" etc.

and then have a script do the following:

1. Write an XML file that contains the main filename, length of the whole file in milliseconds, length and position of each region in the file, name of each comma separated value for each region,

<regname01>01</regname01>
<item>word01</item>
<item>unstressed</item>

and finally write the names of each of the new filenames to be created when each region gets extracted and saved (step 2)

2. Save the regions to separate files named
"mainfilename001.mp3,
"mainfilename002.mp3,
"mainfilename003.mp3, etc


I would then be able to write some general Actionscript that could get all that info from the XML file so Flash knows what files to load, where to put cue points, what text to lay over them, if they are stressed or unstressed.

trying to get my head around the workflow.... any help would be greatly appreciated.

Message last edited on1/7/2007 1:09:50 AM bysound-kobo.
Subject:RE: Region/Marker info to XML for use in Flas
Reply by: _TJ
Date:1/8/2007 5:40:37 PM

Well, if the regions are all going to be in order (i.e. Region01 is before Region02, is before Region03, etc" then you don't need to bother with numbering them.

And you don't need word01, word02 either in their names, unless regions aren't words.

So it looks to me like you would

1) edit the file, creating regions with names like "stessed" "unstressed".

run a script that walks thorough the regions, saving them as files and also
writing the filename and other info into an XML document at the same time.

The script SDK has a sample called "SaveRegionsAsFiles" that will show you how to walk thought the regions list and save each one to a file.

There is also an example called DumpRegionsToFile that shows how to walk through the region list and make a text file containing a line of data for each marker/region. This example uses a simple text file rather than an XML file, but it may be useful to you.

tj







Subject:RE: Region info to XML - more help please...
Reply by: sound-kobo
Date:1/13/2007 6:51:51 AM


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

public class EntryPoint {
public string Begin(IScriptableApp app) {
int cFilesWithMarkers = 0;
ISfFileHost dfile = app.CurrentFile;
string szDir = Path.GetDirectoryName(dfile.Filename);
string sLogFile = PromptForLogFile(@szDir);


if (null == sLogFile)
return "no output filename";

FileInfo fi = new FileInfo(sLogFile);

StreamWriter stm = fi.AppendText();


foreach (ISfFileHost file in app.Files)
{
if (file.MarkerCount > 0)
{

WriteMarkersToStream(stm, file);
cFilesWithMarkers++;

}
else
{
DPF("'{0}' does not contain any markers.", file.Filename);
}
}
stm.Close();


DPF("{0} file(s) affected", cFilesWithMarkers);
return String.Format("{0} file(s) affected. Script {1} is done.", cFilesWithMarkers, Script.Name);
}


public void WriteMarkersToStream(StreamWriter stm, ISfFileHost file)
{
ISfPositionFormatter PosFmt = file.Formatter;
string strFullFilePathName = file.Filename;
string strDirectory = Path.GetDirectoryName(strFullFilePathName);
string strFilename = Path.GetFileName(strFullFilePathName);

stm.WriteLine(String.Format("<file>{0}", strFilename));
stm.WriteLine(String.Format("<markerCount>{0:d2}</markerCount>", file.MarkerCount));

int ii = 0;
foreach (SfAudioMarker mk in file.Markers)
{
string[] arMkrNm = mk.Name.Split(new char[] {';'});
int m = mk.Ident+1;
stm.WriteLine(String.Format("<marker id = '{0}'>", m));
int i=1;
foreach (string item in arMkrNm)
{
stm.WriteLine(" <word>{0}</word>", item);
++i;
}

stm.WriteLine(String.Format(" <startposition>{0}</startposition>", PosFmt.Format(mk.Start)));
stm.WriteLine(String.Format(" <sectionLength>{0}</sectionLength>", PosFmt.Format(mk.Length)));
stm.WriteLine("</marker>");
++ii;
}
stm.WriteLine("</file>");
stm.WriteLine("");
stm.Flush();
}

public string PromptForLogFile(string sDefault)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Title = "Choose output file.";
sfd.FileName = "regions";
sfd.Filter = "XML (*.xml)|*.xml";
sfd.DefaultExt = "xml";
if (DialogResult.OK != sfd.ShowDialog())
return null;

return sfd.FileName;
}

public void FromSoundForge(IScriptableApp app) {
ForgeApp = app; //execution begins here
app.SetStatusText(String.Format("Script '{0}' is running.", Script.Name));
string szMessage = Begin(app);
app.SetStatusText((szMessage != null) ? szMessage : 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, object o) { ForgeApp.OutputText(String.Format(fmt,o)); }
public static void DPF(string fmt, object o, object o2) { ForgeApp.OutputText(String.Format(fmt,o,o2)); }
public static void DPF(string fmt, object o, object o2, object o3) { ForgeApp.OutputText(String.Format(fmt,o,o2,o3)); }
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


Message last edited on1/24/2007 3:33:00 AM bysound-kobo.
Subject:RE: Region info to XML - more help please...
Reply by: sound-kobo
Date:1/24/2007 3:39:57 AM

This script outputs the information that I need almost perfectly. However, I can't figure out how to wrap the whole thing with a start and an end tag to make it nice and tidy as XML.

something like.


<directory name="directoryname">

(... markups for each file and regions here..)

</directory>


Do I need a separate function that calls the "WriteMarkersToStream" function and have that function do it? or, is there a better way?? Thanks.. :)

Subject:RE: Region info to XML - more help please...
Reply by: sound-kobo
Date:1/24/2007 3:41:48 AM

Just to clarify, I open all the files in a folder, run the script on them and save the output as regions.xml.

Go Back