/// <summary> /// Initializes a new instance of the WaveInventoryCreator class. /// </summary> /// <param name="resultFile">The file name of the result files without extension name.</param> /// <param name="header">The wave info header.</param> /// <param name="namedUnitTypeId">The Dictionary which key is unit name and the value is index type id.</param> /// <param name="phoneIdMap">Phone id map .</param> /// <param name="millisecondPerFrame">Millisecond per frame.</param> /// <param name="keepLeftRightFrameMargin">Keep left right frame margin.</param> /// <param name="obfuscationMethod">The given method to perform obfuscation for the wave data.</param> public WaveInventoryCreator(string resultFile, WaveInfoHeader header, IDictionary<string, int> namedUnitTypeId, IDictionary<string, int> phoneIdMap, int millisecondPerFrame, int keepLeftRightFrameMargin, ObfuscationMethod obfuscationMethod) { if (string.IsNullOrEmpty(resultFile)) { throw new ArgumentNullException("resultFile"); } if (header == null) { throw new ArgumentNullException("header"); } if (namedUnitTypeId == null) { throw new ArgumentNullException("namedUnitTypeId"); } if (phoneIdMap == null) { throw new ArgumentNullException("phoneIdMap"); } if (obfuscationMethod == null) { throw new ArgumentNullException("obfuscationMethod"); } if (millisecondPerFrame <= 0) { throw new ArgumentException("millisecondPerFrame"); } if (keepLeftRightFrameMargin < 0) { throw new ArgumentException("keepLeftRightFrameMargin"); } _obfuscationMethod = obfuscationMethod; _header = header; _header.Validate(); _ccMarginLength = (int)(_header.CrossCorrelationMarginLength * 0.001f * _header.SamplesPerSecond); _fsMarginLength = (int)(keepLeftRightFrameMargin * millisecondPerFrame * 0.001f * _header.SamplesPerSecond); _namedUnitTypeId = namedUnitTypeId; _phoneIdMap = phoneIdMap; _indexingFile = new UnitIndexingFile(namedUnitTypeId); _fileName = resultFile; Helper.EnsureFolderExistForFile(_fileName); string fullFileName; switch (_header.Compression) { case WaveCompressCatalog.Unc: fullFileName = _fileName.AppendExtensionName(FileExtensions.WaveInventory); break; default: throw new NotSupportedException("Only Unc is supported"); } _fileStream = new FileStream(fullFileName, FileMode.Create); _writer = new BinaryWriter(_fileStream); _voiceFontHeader = new VoiceFontHeader { FileTag = 0x45564157, // "WAVE" FormatTag = VoiceFontTag.FmtIdUncompressedWaveInventory, Version = 0, Build = 0, DataSize = 0, }; _voiceFontHeader.Save(_writer); _dataOffset = _writer.BaseStream.Position; _millisecondPerFrame = millisecondPerFrame; LogFile = string.Empty; }