private SpeechLipSyncLine CompilePapagayoFile(string fileName, CompileMessages errors)
{
SpeechLipSyncLine syncDataForThisFile = new SpeechLipSyncLine();
syncDataForThisFile.FileName = Path.GetFileNameWithoutExtension(fileName);
string thisLine;
int lineNumber = 0;
StreamReader sr = new StreamReader(fileName);
if ((thisLine = sr.ReadLine()) != null) // Skip over the first line (always a heading)
while ((thisLine = sr.ReadLine()) != null)
{
lineNumber++;
if (thisLine.IndexOf(' ') > 0)
{
string[] parts = thisLine.Split(' ');
int part0;
if (!Int32.TryParse(parts[0], out part0))
{
string friendlyFileName = Path.GetFileName(fileName);
errors.Add(new CompileError("Non-numeric phoneme offset '" + parts[0] + "'", friendlyFileName, lineNumber));
continue;
}
int xpos = part0;
if (xpos < 0) // Clamp negative XPOS to 0
xpos = 0;
int milliSeconds = (part0 * 1000) / 24;
string phonemeCode = parts[1].Trim().ToUpper();
int frameID = FindFrameNumberForPhoneme(phonemeCode);
if (frameID < 0)
{
string friendlyFileName = Path.GetFileName(fileName);
errors.Add(new CompileError("No frame found to match phoneme code '" + phonemeCode + "'", friendlyFileName, lineNumber));
}
else
{
syncDataForThisFile.Phonemes.Add(new SpeechLipSyncPhoneme(milliSeconds, (short)frameID));
}
}
}
sr.Close();
AlignPhonemeOffsets(syncDataForThisFile);
return syncDataForThisFile;
}