/* * /// (non-Javadoc) * * /// @see edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util.props.PropertySheet) */ public override void NewProperties(PropertySheet ps) { LogMath = LogMath.GetLogMath(); _acousticModel = (AcousticModel)ps.GetComponent(PropAcousticModel); Grammar = (Grammar)ps.GetComponent(PropGrammar); UnitManager = (UnitManager)ps.GetComponent(PropUnitManager); // get the rest of the configuration data _logWordInsertionProbability = LogMath.LinearToLog(ps.GetDouble(PropWordInsertionProbability)); LogSilenceInsertionProbability = LogMath.LinearToLog(ps.GetDouble(PropSilenceInsertionProbability)); _logFillerInsertionProbability = LogMath.LinearToLog(ps.GetDouble(PropFillerInsertionProbability)); _logUnitInsertionProbability = LogMath.LinearToLog(ps.GetDouble(PropUnitInsertionProbability)); _languageWeight = ps.GetFloat(PropLanguageWeight); _dumpGStates = ps.GetBoolean(PropDumpGstates); _showCompilationProgress = ps.GetBoolean(PropShowCompilationProgress); _spreadWordProbabilitiesAcrossPronunciations = ps.GetBoolean(PropSpreadWordProbabilitiesAcrossPronunciations); AddOutOfGrammarBranch = ps.GetBoolean(PropAddOutOfGrammarBranch); if (AddOutOfGrammarBranch) { LogOutOfGrammarBranchProbability = LogMath.LinearToLog(ps.GetDouble(PropOutOfGrammarProbability)); LogPhoneInsertionProbability = LogMath.LinearToLog(ps.GetDouble(PropPhoneInsertionProbability)); PhoneLoopAcousticModel = (AcousticModel)ps.GetComponent(PropPhoneLoopAcousticModel); } Name = ps.InstanceName; }
public LexTreeLinguist(AcousticModel acousticModel, UnitManager unitManager, LanguageModel languageModel, IDictionary dictionary, Boolean fullWordHistories, Boolean wantUnigramSmear, double wordInsertionProbability, double silenceInsertionProbability, double fillerInsertionProbability, double unitInsertionProbability, float languageWeight, Boolean addFillerWords, Boolean generateUnitStates, float unigramSmearWeight, int maxArcCacheSize) { _acousticModel = acousticModel; _logMath = LogMath.GetLogMath(); _unitManager = unitManager; LanguageModel = languageModel; Dictionary = dictionary; //this.fullWordHistories = fullWordHistories; _wantUnigramSmear = wantUnigramSmear; _logWordInsertionProbability = _logMath.LinearToLog(wordInsertionProbability); _logSilenceInsertionProbability = _logMath.LinearToLog(silenceInsertionProbability); _logFillerInsertionProbability = _logMath.LinearToLog(fillerInsertionProbability); _logUnitInsertionProbability = _logMath.LinearToLog(unitInsertionProbability); LanguageWeight = languageWeight; AddFillerWords = addFillerWords; GenerateUnitStates = generateUnitStates; _unigramSmearWeight = unigramSmearWeight; _maxArcCacheSize = maxArcCacheSize; CacheEnabled = maxArcCacheSize > 0; if (CacheEnabled) { ArcCache = new LRUCache <LexTreeState, ISearchStateArc[]>(maxArcCacheSize); } }
public AFlatLinguist(AcousticModel acousticModel, Grammar grammar, UnitManager unitManager, double wordInsertionProbability, double silenceInsertionProbability, double unitInsertionProbability, double fillerInsertionProbability, float languageWeight, bool addOutOfGrammarBranch, double outOfGrammarBranchProbability, double phoneInsertionProbability, AcousticModel phoneLoopAcousticModel) { this.runtime = Runtime.getRuntime(); this.counterForMemoryLogging = 0L; this.EMPTY_ARCS = new SearchStateArc[0]; this.successorCache = new HashMap(); this.logger = Logger.getLogger(Object.instancehelper_getClass(this).getName()); this.acousticModel = acousticModel; this.grammar = grammar; this.unitManager = unitManager; LogMath logMath = LogMath.getLogMath(); this.logWordInsertionProbability = logMath.linearToLog(wordInsertionProbability); this.logSilenceInsertionProbability = logMath.linearToLog(silenceInsertionProbability); this.logUnitInsertionProbability = logMath.linearToLog(unitInsertionProbability); this.logFillerInsertionProbability = logMath.linearToLog(fillerInsertionProbability); this.languageWeight = languageWeight; this.addOutOfGrammarBranch = addOutOfGrammarBranch; this.logOutOfGrammarBranchProbability = logMath.linearToLog(outOfGrammarBranchProbability); this.logPhoneInsertionProbability = logMath.linearToLog((double)this.logPhoneInsertionProbability); if (addOutOfGrammarBranch) { this.phoneLoopAcousticModel = phoneLoopAcousticModel; } }
/* * /// (non-Javadoc) * * /// @see edu.cmu.sphinx.util.props.Configurable#newProperties(edu.cmu.sphinx.util.props.PropertySheet) */ public override void NewProperties(PropertySheet ps) { _logMath = LogMath.GetLogMath(); _acousticModel = (AcousticModel)ps.GetComponent(PropAcousticModel); _unitManager = (UnitManager)ps.GetComponent(PropUnitManager); LanguageModel = (LanguageModel)ps.GetComponent(PropLanguageModel); Dictionary = (IDictionary)ps.GetComponent(PropDictionary); //fullWordHistories = ps.getBoolean(PROP_FULL_WORD_HISTORIES); _wantUnigramSmear = ps.GetBoolean(PropWantUnigramSmear); _logWordInsertionProbability = _logMath.LinearToLog(ps.GetDouble(PropWordInsertionProbability)); _logSilenceInsertionProbability = _logMath.LinearToLog(ps.GetDouble(PropSilenceInsertionProbability)); _logFillerInsertionProbability = _logMath.LinearToLog(ps.GetDouble(PropFillerInsertionProbability)); _logUnitInsertionProbability = _logMath.LinearToLog(ps.GetDouble(PropUnitInsertionProbability)); LanguageWeight = ps.GetFloat(PropLanguageWeight); AddFillerWords = (ps.GetBoolean(PropAddFillerWords)); GenerateUnitStates = (ps.GetBoolean(PropGenerateUnitStates)); _unigramSmearWeight = ps.GetFloat(PropUnigramSmearWeight); _maxArcCacheSize = ps.GetInt(PropCacheSize); CacheEnabled = _maxArcCacheSize > 0; if (CacheEnabled) { ArcCache = new LRUCache <LexTreeState, ISearchStateArc[]>(_maxArcCacheSize); } }
public FlatLinguist(AcousticModel acousticModel, Grammar grammar, UnitManager unitManager, double wordInsertionProbability, double silenceInsertionProbability, double fillerInsertionProbability, double unitInsertionProbability, float languageWeight, Boolean dumpGStates, Boolean showCompilationProgress, Boolean spreadWordProbabilitiesAcrossPronunciations, Boolean addOutOfGrammarBranch, double outOfGrammarBranchProbability, double phoneInsertionProbability, AcousticModel phoneLoopAcousticModel) { _acousticModel = acousticModel; LogMath = LogMath.GetLogMath(); Grammar = grammar; UnitManager = unitManager; _logWordInsertionProbability = LogMath.LinearToLog(wordInsertionProbability); LogSilenceInsertionProbability = LogMath.LinearToLog(silenceInsertionProbability); _logFillerInsertionProbability = LogMath.LinearToLog(fillerInsertionProbability); _logUnitInsertionProbability = LogMath.LinearToLog(unitInsertionProbability); _languageWeight = languageWeight; _dumpGStates = dumpGStates; _showCompilationProgress = showCompilationProgress; _spreadWordProbabilitiesAcrossPronunciations = spreadWordProbabilitiesAcrossPronunciations; AddOutOfGrammarBranch = addOutOfGrammarBranch; if (addOutOfGrammarBranch) { LogOutOfGrammarBranchProbability = LogMath.LinearToLog(outOfGrammarBranchProbability); LogPhoneInsertionProbability = LogMath.LinearToLog(phoneInsertionProbability); PhoneLoopAcousticModel = phoneLoopAcousticModel; } Name = null; }
public BuildTranscriptHMM(string context, Transcript transcript, AcousticModel acousticModel, UnitManager unitManager) { this.acousticModel = acousticModel; this.unitManager = unitManager; this.wordGraph = this.buildWordGraph(transcript); if (!BuildTranscriptHMM.assertionsDisabled && !this.wordGraph.validate()) { object obj = "Word graph not validated"; throw new AssertionError(obj); } this.phonemeGraph = this.buildPhonemeGraph(this.wordGraph); if (!BuildTranscriptHMM.assertionsDisabled && !this.phonemeGraph.validate()) { object obj2 = "Phone graph not validated"; throw new AssertionError(obj2); } this.contextDependentPhoneGraph = this.buildContextDependentPhonemeGraph(this.phonemeGraph); if (!BuildTranscriptHMM.assertionsDisabled && !this.contextDependentPhoneGraph.validate()) { object obj3 = "Context dependent graph not validated"; throw new AssertionError(obj3); } this.hmmGraph = this.buildHMMGraph(this.contextDependentPhoneGraph); if (!BuildTranscriptHMM.assertionsDisabled && !this.hmmGraph.validate()) { object obj4 = "HMM graph not validated"; throw new AssertionError(obj4); } }
/** * Creates the CIPhoneLoop with the given acoustic model and phone insertion probability * * @param model the acoustic model * @param logPhoneInsertionProbability the insertion probability */ public PhoneLoopCI(AcousticModel model, float logPhoneInsertionProbability, SentenceHMMState initialState) { this.model = model; this.logPhoneInsertionProbability = logPhoneInsertionProbability; this.inititalState = initialState; }
public UtteranceHMMGraph(string context, Utterance utterance, AcousticModel acousticModel, UnitManager unitManager) { utterance.startTranscriptIterator(); while (utterance.hasMoreTranscripts()) { Transcript transcript = utterance.nextTranscript(); TranscriptHMMGraph transcriptGraph = new TranscriptHMMGraph(context, transcript, acousticModel, unitManager); this.add(transcriptGraph); } }
public OutOfGrammarGraph(AcousticModel model, float logOutOfGrammarBranchProbability, float logPhoneInsertionProbability) { this.acousticModel = model; this.logOutOfGrammarBranchProbability = logOutOfGrammarBranchProbability; this.logPhoneInsertionProbability = logPhoneInsertionProbability; this.fbs = new OutOfGrammarGraph.FirstBranchState(this); this.lbs = new OutOfGrammarGraph.LastBranchState(this); this.uws = new OutOfGrammarGraph.UnknownWordState(this); this.lbsArcSet = new SearchStateArc[1]; this.lbsArcSet[0] = this.lbs; }
public PhoneLoop(AcousticModel model, float logOutOfGrammarBranchProbability, float logPhoneInsertionProbability, SearchStateArc[] toGrammarSearchState) { this.acousticModel = model; this.logOutOfGrammarBranchProbability = logOutOfGrammarBranchProbability; this.logPhoneInsertionProbability = logPhoneInsertionProbability; this.toGrammarSearchState = toGrammarSearchState; this.fbs = new PhoneLoop.FirstBranchState(this); this.lbs = new PhoneLoop.LastBranchState(this); this.uws = new PhoneLoop.UnknownWordState(this); this.lbsArcSet = new SearchStateArc[1]; this.lbsArcSet[0] = this.lbs; }
private void CreateContextDependentSuccessors() { _cdHMMs = new HashMap <Unit, HashMap <Unit, List <IHMM> > >(); _senonesToUnits = new HashMap <SenoneSequence, List <Unit> >(); _fillerHMMs = new List <IHMM>(); _leftContextSilHMMs = new List <IHMM>(); var hmmIter = AcousticModel.GetHMMIterator(); while (hmmIter.MoveNext()) { IHMM hmm = hmmIter.Current; List <Unit> sameSenonesUnits; SenoneSequence senoneSeq = ((SenoneHMM)hmm).SenoneSequence; if ((sameSenonesUnits = _senonesToUnits.Get(senoneSeq)) == null) { sameSenonesUnits = new List <Unit>(); _senonesToUnits.Put(senoneSeq, sameSenonesUnits); } sameSenonesUnits.Add(hmm.Unit as Unit); if (hmm.Unit.IsFiller) { _fillerHMMs.Add(hmm); continue; } if (hmm.Unit.IsContextDependent()) { LeftRightContext context = (LeftRightContext)hmm.Unit.Context; Unit lc = context.LeftContext[0] as Unit; if (lc == UnitManager.Silence) { _leftContextSilHMMs.Add(hmm); continue; } Unit baseUnit = hmm.Unit.BaseUnit as Unit; HashMap <Unit, List <IHMM> > lcSuccessors; if ((lcSuccessors = _cdHMMs.Get(lc)) == null) { lcSuccessors = new HashMap <Unit, List <IHMM> >(); _cdHMMs.Put(lc, lcSuccessors); } List <IHMM> lcBaseSuccessors; if ((lcBaseSuccessors = lcSuccessors.Get(baseUnit)) == null) { lcBaseSuccessors = new List <IHMM>(); lcSuccessors.Put(baseUnit, lcBaseSuccessors); } lcBaseSuccessors.Add(hmm); } } _leftContextSilHMMs.AddRange(_fillerHMMs); }
public void UploadAcousticDataset(string datasetUrl, string speechKey, AcousticModel model) { var parameters = ToDictionary(model); var trainer = new DatasetUpload(); var response = trainer.MultipartFormDataPost(datasetUrl, speechKey, parameters); // Process response StreamReader responseReader = new StreamReader(response.GetResponseStream()); string fullResponse = responseReader.ReadToEnd(); response.Close(); Console.WriteLine($"HttpResponse: {fullResponse}"); }
public static AcousticModel CreateAcousticModel(SpeechModel model, byte[] zipFile, byte[] transcriptionFile) { var acousticModel = new AcousticModel() { name = model.name, description = model.description, locale = model.locale, dataImportKind = "Acoustic", properties = model.properties, audiodata = zipFile, transcriptions = transcriptionFile }; return(acousticModel); }
private static AcousticModel GetAcousticModel() { var properties = new Dictionary <string, string>(); properties.Add("ProfanityFilterMode", "Masked"); properties.Add("PunctuationMode", "DictatedAndAutomatic"); var speechModel = new AcousticModel() { name = "Test", description = "Test Description", locale = "en-US", dataImportKind = "Acoustic", properties = properties }; return(speechModel); }
static void Main(string[] args) { Encoding encoding = Encoding.UTF8; var languageBytes = encoding.GetBytes(File.ReadAllText(PathToLanguageTranscript, Encoding.UTF8)); var transcriptBytes = encoding.GetBytes(File.ReadAllText(PathToAudioTranscript, Encoding.UTF8)); var zipBytes = File.ReadAllBytes(PathToZipFile); var modelHelper = new ModelHelper(); LanguageModel languageModel = GetLanguageModel(); AcousticModel acousticModel = GetAcousticModel(); languageModel = ModelHelper.CreateLanguageModel(languageModel, languageBytes); acousticModel = ModelHelper.CreateAcousticModel(acousticModel, zipBytes, transcriptBytes); modelHelper.UploadLanguageDataset(DatasetUrl, SpeechKey, languageModel); modelHelper.UploadAcousticDataset(DatasetUrl, SpeechKey, acousticModel); }
/** Constructs a phone loop search graph. */ public PhoneLoopSearchGraph(SentenceHMMState initState, AcousticModel model, float logPhoneInsertionProbability) { this.inititalState = initState; this.model = model; this.logPhoneInsertionProbability = logPhoneInsertionProbability; existingStates = new Dictionary <string, SearchState>(); firstState = new UnknownWordState(); SentenceHMMState branchState = new BranchOutState(firstState); attachState(firstState, branchState, logOne, logOne); SentenceHMMState lastState = new LoopBackState(firstState); //lastState.setFinalState(true); //attachState(lastState, branchState, LogMath.getLogZero(), // LogMath.getLogZero()); attachState(lastState, inititalState, logOne, logOne); for (java.util.Iterator i = model.getContextIndependentUnitIterator(); i.hasNext();) { Unit unit = (Unit)i.next(); UnitState unitState = new UnitState(unit, HMMPosition.UNDEFINED); // attach unit state to the branch out state attachState(branchState, unitState, logOne, logPhoneInsertionProbability); HMM hmm = model.lookupNearestHMM (unitState.getUnit(), unitState.getPosition(), false); HMMState initialState = hmm.getInitialState(); HMMStateState hmmTree = new HMMStateState(unitState, initialState); addStateToCache(hmmTree); // attach first HMM state to the unit state attachState(unitState, hmmTree, logOne, logOne); // expand the HMM tree HMMStateState finalState = expandHMMTree(unitState, hmmTree); // attach final state of HMM tree to the loopback state attachState(finalState, lastState, logOne, logOne); } }
public override void saveModels(string context) { if (1 == this.acousticModels.size()) { ((TrainerAcousticModel)this.acousticModels.get(0)).save(null); } else { Iterator iterator = this.acousticModels.iterator(); while (iterator.hasNext()) { AcousticModel acousticModel = (AcousticModel)iterator.next(); if (acousticModel is TrainerAcousticModel) { TrainerAcousticModel trainerAcousticModel = (TrainerAcousticModel)acousticModel; trainerAcousticModel.save(acousticModel.getName()); } } } }
private void CreateContextIndependentSuccessors() { var hmmIter = AcousticModel.GetHMMIterator(); CISuccessors = new List <IHMM>(); _senonesToUnits = new HashMap <SenoneSequence, List <Unit> >(); while (hmmIter.MoveNext()) { IHMM hmm = hmmIter.Current; if (!hmm.Unit.IsContextDependent()) { List <Unit> sameSenonesUnits; SenoneSequence senoneSeq = ((SenoneHMM)hmm).SenoneSequence; if ((sameSenonesUnits = _senonesToUnits.Get(senoneSeq)) == null) { sameSenonesUnits = new List <Unit>(); _senonesToUnits.Put(senoneSeq, sameSenonesUnits); } sameSenonesUnits.Add(hmm.Unit as Unit); CISuccessors.Add(hmm); } } }
public FlatLinguist(AcousticModel acousticModel, Grammar grammar, UnitManager unitManager, double wordInsertionProbability, double silenceInsertionProbability, double fillerInsertionProbability, double unitInsertionProbability, float languageWeight, bool dumpGStates, bool showCompilationProgress, bool spreadWordProbabilitiesAcrossPronunciations, bool addOutOfGrammarBranch, double outOfGrammarBranchProbability, double phoneInsertionProbability, AcousticModel phoneLoopAcousticModel) { this.showCompilationProgress = true; this.acousticModel = acousticModel; this.logMath = LogMath.getLogMath(); this.grammar = grammar; this.unitManager = unitManager; this.logWordInsertionProbability = this.logMath.linearToLog(wordInsertionProbability); this.logSilenceInsertionProbability = this.logMath.linearToLog(silenceInsertionProbability); this.logFillerInsertionProbability = this.logMath.linearToLog(fillerInsertionProbability); this.logUnitInsertionProbability = this.logMath.linearToLog(unitInsertionProbability); this.languageWeight = languageWeight; this.dumpGStates = dumpGStates; this.showCompilationProgress = showCompilationProgress; this.spreadWordProbabilitiesAcrossPronunciations = spreadWordProbabilitiesAcrossPronunciations; this.addOutOfGrammarBranch = addOutOfGrammarBranch; if (addOutOfGrammarBranch) { this.logOutOfGrammarBranchProbability = this.logMath.linearToLog(outOfGrammarBranchProbability); this.logPhoneInsertionProbability = this.logMath.linearToLog(phoneInsertionProbability); this.phoneLoopAcousticModel = phoneLoopAcousticModel; } this.name = null; }
public HMMPool(AcousticModel model, Logger logger, UnitManager unitManager) { this.logger = logger; int num = 0; this.model = model; this.unitManager = unitManager; if (model.getLeftContextSize() != 1) { string text = "LexTreeLinguist: Unsupported left context size"; throw new Error(text); } if (model.getRightContextSize() != 1) { string text2 = "LexTreeLinguist: Unsupported right context size"; throw new Error(text2); } Iterator iterator = model.getContextIndependentUnitIterator(); while (iterator.hasNext()) { Unit unit = (Unit)iterator.next(); logger.fine(new StringBuilder().append("CI unit ").append(unit).toString()); if (unit.getBaseID() > num) { num = unit.getBaseID(); } } this.numCIUnits = num + 1; this.unitTable = new Unit[this.numCIUnits * this.numCIUnits * this.numCIUnits]; iterator = model.getHMMIterator(); while (iterator.hasNext()) { HMM hmm = (HMM)iterator.next(); Unit unit2 = hmm.getUnit(); int id = this.getID(unit2); this.unitTable[id] = unit2; if (logger.isLoggable(Level.FINER)) { logger.finer(new StringBuilder().append("Unit ").append(unit2).append(" id ").append(id).toString()); } } this.hmmTable = new EnumMap(ClassLiteral <HMMPosition> .Value); HMMPosition[] array = HMMPosition.values(); int num2 = array.Length; for (int i = 0; i < num2; i++) { HMMPosition hmmposition = array[i]; HMM[] array2 = new HMM[this.unitTable.Length]; this.hmmTable.put(hmmposition, array2); for (int j = 1; j < this.unitTable.Length; j++) { Unit unit3 = this.unitTable[j]; if (unit3 == null) { unit3 = this.synthesizeUnit(j); } if (unit3 != null) { array2[j] = model.lookupNearestHMM(unit3, hmmposition, false); if (!HMMPool.assertionsDisabled && array2[j] == null) { throw new AssertionError(); } } } } }
public CIPhoneLoop(AcousticModel model, float logPhoneInsertionProbability) { this.__logOne = 0f; this.__model = model; this.logPhoneInsertionProbability = logPhoneInsertionProbability; }
/** * /// Creates the CIPhoneLoop with the given acoustic model and phone insertion probability * * /// @param model the acoustic model * /// @param logPhoneInsertionProbability the insertion probability */ public CIPhoneLoop(AcousticModel model, float logPhoneInsertionProbability) { Model = model; LogPhoneInsertionProbability = logPhoneInsertionProbability; }
Dictionary <string, object> ToDictionary(AcousticModel model) { return(ModelToDictionary(model)); }
public TranscriptHMMGraph(string context, Transcript transcript, AcousticModel acousticModel, UnitManager unitManager) { BuildTranscriptHMM buildTranscriptHMM = new BuildTranscriptHMM(context, transcript, acousticModel, unitManager); this.copyGraph(buildTranscriptHMM.getGraph()); }