Code:
import java.io.*;
class PWIEmbeddedWAVExport
{
public static void main(String[] s) throws Exception
{
FileInputStream fis = new FileInputStream (s[0]);
File f = new File (s[0]);
int fileSize = (int)f.length();
byte[] barr = new byte[fileSize];
byte[] barr2 = new byte[fileSize/2];
int readCount = fis.read(barr);
for (int i=0; i<fileSize/2; i++)
barr2[i]=barr[i*2];
String str = new String(barr2);
java.util.Vector indeces = new java.util.Vector();
int lastIndexFound = 0;
while ((lastIndexFound = str.indexOf("VoiceNote.wav", lastIndexFound+1)) != -1)
indeces.addElement(new Integer(lastIndexFound*2));
// now, we have the exact position of all VoiceNote.wav's in the file;
// we can go on for the actual extraction
int sumSize = 0;
for (int i=0; i<indeces.size(); i++)
{
int embFileStartsAt = ((Integer)indeces.elementAt(i)).intValue()+ "VoiceNote.wav".length()*2-2 + 4146 + 4;
int embFileEndsAt = readCount;
if (i<indeces.size()-1) embFileEndsAt = ((Integer)indeces.elementAt(i+1)).intValue() - 528;
FileOutputStream fos = new FileOutputStream (s[0].substring(0, s[0].length()-4)+(indeces.size()-i)+".wav");
// indeces.size()-i is needed because of the LIFO order in the file
fos.write(barr, embFileStartsAt, embFileEndsAt-embFileStartsAt);
fos.flush();
fos.close();
}
fis.close();
} // main
}// class
Feel free to compile (preferably with JDK1.1 if you need 100% compliance with all of the PPC JVM's - please note that I deliberately made it JDK1.1-compliant for the best compliance with current PPC JVM's) and JAR it. To make your life easier, you can also download it from
here.
On the desktop, put it in the classpath and issue the
java -jar PWIEmbeddedWAVExport.jar <PWI name>
command. The extracted sound files will be created in the current directory.
If you plan to do the extraction on the PDA so that you don't need to have access to any desktop computer, you can use any of the following four JVM's (others may also work): NetFront 3.1+, CrEme, Jeode, J9 PJava. Please read
this thread for more information on getting them if you don't have any of them (not even the Java-enabled Netfront - perhaps this is the best solution because you may already have it on your Pocket PC, which makes it unnecessary to install another JVM.
To run the converter on the PDA, make a directory in it with the name, say,
\conv in there. Copy the JAR file and one of the following batch files (I've also listed their contents here).
NetFront jvlite (tested with NF 3.1):
"\Program Files\NetFront3\jvlite.exe" -classpath \conv\PWIEmbeddedWAVExport.jar PWIEmbeddedWAVExport %1
CrEme 3.x/4.x (tested with 3.26):
"\SD-MMCard\creme\bin\CrEme.exe" -Ob -classpath \conv\PWIEmbeddedWAVExport.jar PWIEmbeddedWAVExport %1
Jeode (tested with 1.7.3):
\SD-MMCard\jeode\evm.exe -Djeode.evm.console.local.keep=true -cp \conv\PWIEmbeddedWAVExport.jar PWIEmbeddedWAVExport %1
IBM J9 PJ (tested with 5.7.2):
"\SD-MMCard\IBM PPRO10\bin\J9.exe" "-jcl
pro10" -cp \conv\PWIEmbeddedWAVExport.jar PWIEmbeddedWAVExport %1
Please modify the path to the executable according to the directory your JVM/NetFront is installed to!
The next step is installing
PPC Command Shell - please see my post on doing this
here (second page, third post) - to provide a console to run batch files to avoid the need for editing link files with wired-in filenames.
After installing it, fire up the console and go to
\conv. Assuming you've already copied here the .BAT batch file(s) you want to invoke your JVM('s) with, PWIEmbeddedWAVExport.jar and the source PWI file(s), you can start working right away by issuing the
<batchname> \conv\<PWI name> command. (Note that you need to supply the full directory path, here, \conv to the JVM so that it finds the input file.) The embedded WAV files will be created in the same directory.
I may rewrite/repackage this app using the CF framework some day (but not in the very near future!).