Exemplo n.º 1
0
        static OtoSet ParseOtoSet(StreamReader streamReader)
        {
            OtoSet otoSet = new OtoSet();

            while (!streamReader.EndOfStream)
            {
                var line = streamReader.ReadLine();
                Oto oto  = ParseOto(line);
                if (oto != null)
                {
                    otoSet.Otos.Add(oto);
                }
            }
            return(otoSet);
        }
Exemplo n.º 2
0
        public static OtoSet ParseOtoSet(Stream stream, string filePath, Encoding encoding)
        {
            OtoSet otoSet;

            using (var reader = new StreamReader(stream, encoding)) {
                var fileLoc = new FileLoc {
                    file = filePath, lineNumber = 0
                };
                otoSet = new OtoSet()
                {
                    File = filePath,
                };
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    fileLoc.line = line;
                    try {
                        Oto oto = ParseOto(line);
                        if (oto != null)
                        {
                            otoSet.Otos.Add(oto);
                        }
                    } catch (Exception e) {
                        Log.Error(e, $"Failed to parse\n{fileLoc}");
                        otoSet.Errors.Add($"Oto error:\n{fileLoc}");
                    }
                    fileLoc.line = null;
                    fileLoc.lineNumber++;
                }
            }
            // Use filename as alias if not in oto.
            var knownFiles = otoSet.Otos.Select(oto => oto.Wav).ToHashSet();

            foreach (var wav in Directory.EnumerateFiles(Path.GetDirectoryName(filePath), "*.wav", SearchOption.TopDirectoryOnly))
            {
                var file = Path.GetFileName(wav);
                if (!knownFiles.Contains(file))
                {
                    var oto = new Oto {
                        Alias = Path.GetFileNameWithoutExtension(file),
                        Wav   = file,
                    };
                    oto.Phonetic = oto.Alias;
                    otoSet.Otos.Add(oto);
                }
            }
            return(otoSet);
        }
Exemplo n.º 3
0
        static OtoSet ParseOtoSet(StreamReader streamReader, FileLoc fileLoc)
        {
            OtoSet otoSet = new OtoSet();

            while (!streamReader.EndOfStream)
            {
                var line = streamReader.ReadLine();
                fileLoc.line = line;
                try {
                    Oto oto = ParseOto(line);
                    if (oto != null)
                    {
                        otoSet.Otos.Add(oto);
                    }
                } catch (Exception e) {
                    throw new FileFormatException($"Failed to parse\n{fileLoc}", e);
                }
                fileLoc.line = null;
                fileLoc.lineNumber++;
            }
            return(otoSet);
        }