Exemple #1
0
        /// <summary>
        /// Parse all files in the directory path to input pairs.
        /// </summary>
        /// <param name="language">Language information about the files.</param>
        /// <param name="path">Path to the directory that holds all the wem and cr2w files.</param>
        /// <returns>Information about all the wem and cr2w pairs found in the directory.</returns>
        /// <exception cref="Exception">Something happened.</exception>
        public static IEnumerable <WemCr2wInputPair> CollectDirectory(W3Language language, String path)
        {
            var dot = new char[] { '.' };
            var ob  = new char[] { '[' };
            var cb  = new char[] { ']' };
            var op  = new char[] { '(' };
            var cp  = new char[] { ')' };

            return(Directory
                   .GetFiles(path)
                   .Where(file => file.EndsWith(".wem") || file.EndsWith(".cr2w"))
                   .GroupBy(file => Path.GetFileName(file).Split(dot).First().Split(ob).First().Split(op).First())
                   .Select(paths =>
            {
                var specific_id = LanguageTools.Convert(new LanguageNeutralID((UInt32)long.Parse(paths.Key)), language);
                var wem_path = paths.First(p => p.EndsWith(".wem"));
                var cr2w_path = paths.First(p => p.EndsWith(".cr2w"));
                var wem = new FileInfo(wem_path);
                var cr2w = new FileInfo(cr2w_path);
                var id_high = (UInt32)long.Parse(wem_path.Split(op).Last().Split(cp).First());
                var duration = float.Parse(wem_path.Split(ob).Last().Split(cb).First(), CultureInfo.InvariantCulture.NumberFormat);
                return new WemCr2wInputPair(specific_id, id_high, () => wem.OpenRead(), (UInt32)wem.Length, duration, () => cr2w.OpenRead(), (UInt32)cr2w.Length);
            })
                   .OrderBy(input_pair => input_pair.id.value)
                   .ToList()
                   .AsReadOnly());
        }
Exemple #2
0
        /// <summary>
        /// Unpacks the w3speech file into the directory.
        /// </summary>
        /// <param name="directory">The directory where the new wem and cr2w files will be unpacked into.</param>
        /// <param name="w3speech_file">The w3speech file to unpack.</param>
        /// <param name="languages">Information about the known languages. The right one will be selected automatically.</param>
        /// <exception cref="Exception">Something happened.</exception>
        public static void UnpackW3SpeechFile(String directory, String w3speech_file, IEnumerable <W3Language> languages)
        {
            var input    = new BinaryReader(new FileStream(w3speech_file, FileMode.Open));
            var info     = Coder.Decode(new W3Speech(w3speech_file), input);
            var language = languages.First(lang => lang.Key.value == info.language_key.value);
            var dir      = directory.EndsWith("\\") ? directory : directory + "\\";

            info.item_infos.ToList().ForEach(item =>
            {
                var neutral_id    = LanguageTools.Convert(item.id, language);
                var wem_file_name = neutral_id.value.ToString("D10") + "[" + item.duration.ToString("R", CultureInfo.InvariantCulture) + "](" + item.id_high.ToString("D10") + ").wem";
                var wem_output    = new BinaryWriter(new FileStream(dir + wem_file_name, FileMode.Create));
                input.BaseStream.Seek((int)item.wem_offs, SeekOrigin.Begin);
                StreamTools.Transfer(item.wem_size, input.BaseStream, wem_output.BaseStream);
                wem_output.Close();

                var cr2w_file_name = neutral_id.value.ToString("D10") + "(" + item.id_high.ToString("D10") + ").cr2w";
                var cr2w_output    = new BinaryWriter(new FileStream(dir + cr2w_file_name, FileMode.Create));
                input.BaseStream.Seek((int)item.cr2w_offs, SeekOrigin.Begin);
                StreamTools.Transfer(item.cr2w_size, input.BaseStream, cr2w_output.BaseStream);
                cr2w_output.Close();
            });
            input.Close();
        }