コード例 #1
0
ファイル: WordEventHandler.cs プロジェクト: Wysepka/HangTanks
 public void InvokeWordTypedResult(WordResult wordResult)
 {
     if (wordTypedResult != null)
     {
         wordTypedResult.Invoke(wordResult);
     }
 }
コード例 #2
0
        public IList <WordResult> Execute(IWordDictionary dictionary)
        {
            var result        = new WordResult("Length");
            var nospaceResult = new WordResult("Length (without word including space)");
            var list          = new List <WordResult>();

            if (_settings.IncludeSpace != "no")
            {
                list.Add(result);
            }

            if (_settings.IncludeSpace != "yes")
            {
                list.Add(nospaceResult);
            }

            foreach (var word in dictionary.Words)
            {
                var lengthStr = word.Length.ToString("0000");

                if (_settings.IncludeSpace != "no")
                {
                    result.CountUp(lengthStr);
                }

                if (_settings.IncludeSpace != "yes" && !word.Any(x => char.IsWhiteSpace(x)))
                {
                    nospaceResult.CountUp(lengthStr);
                }
            }

            return(list);
        }
コード例 #3
0
    private void AssociateWordResultsWithBehaviours()
    {
        List <Word> list = new List <Word>(this.mWaitingQueue);

        foreach (Word word in list)
        {
            if (this.mTrackedWords.ContainsKey(word.ID))
            {
                WordResult wordResult = this.mTrackedWords[word.ID];
                if (this.AssociateWordBehaviour(wordResult) != null)
                {
                    this.mWaitingQueue.Remove(word);
                }
            }
            else
            {
                this.mWaitingQueue.Remove(word);
            }
        }
        foreach (WordResult result2 in this.mNewWords)
        {
            if (this.AssociateWordBehaviour(result2) == null)
            {
                this.mWaitingQueue.Add(result2.Word);
            }
        }
    }
コード例 #4
0
        public static void main(string[] args)
        {
            [email protected]("Loading models...");
            Configuration configuration = new Configuration();

            configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
            configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
            Context context = new Context(configuration);

            context.setLocalProperty("decoder->searchManager", "allphoneSearchManager");
            Recognizer  recognizer       = (Recognizer)context.getInstance(ClassLiteral <Recognizer> .Value);
            InputStream resourceAsStream = ClassLiteral <AllphoneDemo> .Value.getResourceAsStream("/edu/cmu/sphinx/demo/aligner/10001-90210-01803.wav");

            resourceAsStream.skip((long)((ulong)44));
            recognizer.allocate();
            context.setSpeechSource(resourceAsStream, TimeFrame.INFINITE);
            Result result;

            while ((result = recognizer.recognize()) != null)
            {
                SpeechResult speechResult = new SpeechResult(result);
                [email protected]("Hypothesis: %s\n", new object[]
                {
                    speechResult.getHypothesis()
                });
                [email protected]("List of recognized words and their times:");
                Iterator iterator = speechResult.getWords().iterator();
                while (iterator.hasNext())
                {
                    WordResult wordResult = (WordResult)iterator.next();
                    [email protected](wordResult);
                }
            }
            recognizer.deallocate();
        }
コード例 #5
0
    private WordAbstractBehaviour AssociateWordBehaviour(WordResult wordResult)
    {
        List <WordAbstractBehaviour> list;
        string key = wordResult.Word.StringValue.ToLowerInvariant();

        if (this.mWordBehaviours.ContainsKey(key))
        {
            list = this.mWordBehaviours[key];
        }
        else if (this.mWordBehaviours.ContainsKey("Template_ID"))
        {
            list = this.mWordBehaviours["Template_ID"];
        }
        else
        {
            Debug.Log("No prefab available for string value " + key);
            return(null);
        }
        foreach (WordAbstractBehaviour behaviour in list)
        {
            if (behaviour.Trackable == null)
            {
                return(this.AssociateWordBehaviour(wordResult, behaviour));
            }
        }
        if (list.Count < this.mMaxInstances)
        {
            WordAbstractBehaviour item = InstantiateWordBehaviour(list.First <WordAbstractBehaviour>());
            list.Add(item);
            return(this.AssociateWordBehaviour(wordResult, item));
        }
        return(null);
    }
コード例 #6
0
        public WordResult CheckWordsFormationByString(string sentence, StringBuilder sb)
        {
            //base case
            if (sentence.Length == 0)
            {
                return(new WordResult(true, sb.ToString()));
            }

            //find all the possible prefixes for the given string..eg ilike
            //i , il, ili, ilk, ilike  using string.substring
            for (int i = 1; i <= sentence.Length; i++)
            {
                //sec pram is length
                string prefix = sentence.Substring(0, i);
                if (IsWordExistsInDictionary(prefix))
                {
                    sb.Append(prefix).Append(" ");

                    WordResult result = CheckWordsFormationByString(sentence.Substring(i, sentence.Length - i), sb);
                    if (result.CanFormWords)
                    {
                        return(result);
                    }
                    else
                    {
                        sb.Clear();
                    }
                }
            }

            //we checked all the possible prefixes no words can be formed
            return(new WordResult(false, string.Empty));
        }
コード例 #7
0
        public WordResult IntToWord([FromBody] IntInput numberInput)
        {
            var wordResult = new WordResult();

            if (string.IsNullOrWhiteSpace(numberInput.Number))
            {
                wordResult.Message  = "Please provide a valid number that larger than 0.";
                Response.StatusCode = 400;
                return(wordResult);
            }

            try
            {
                wordResult.Result = NumberTextConverter.IntegerToWritten(numberInput.Number);
            }
            catch (NumberTextConverterException e)
            {
                wordResult.Message  = e.Message;
                Response.StatusCode = 400;
                return(wordResult);
            }
            catch
            {
                wordResult.Message  = "Internal Server Error";
                Response.StatusCode = 500;
                return(wordResult);
            }

            return(wordResult);
        }
コード例 #8
0
        //[Authorize]
        public async Task <IActionResult> Get(String word, [FromQuery] Int32 hid = 0, [FromQuery] Int32 sid = 0)
        {
            if (hid <= 0)
            {
                return(BadRequest("Not HID inputted"));
            }

            // Basic check
            WordSource src = (WordSource)sid;

            switch (src)
            {
            case WordSource.Bing:
            case WordSource.Iciba:
            {
                // Fetch the result
                WordResult wr = await this.FetchWordFromSourceAsync(word, src);

                // After then,
                return(new JsonResult(wr));
            }

            default:
                return(BadRequest("No such source yet!"));
            }
        }
コード例 #9
0
        private void ApplyWordResult(WordResult wordResult)
        {
            if (viewerWordInformation.Visibility != Visibility.Visible)
            {
                viewerWordInformation.Visibility  = Visibility.Visible;
                panelRetrivationFailed.Visibility = Visibility.Collapsed;
            }

            string word = wordResult.Word;

            textWordTitle.Text = word;

            WordPronunciationsCollection pron = wordResult.Pronunciations;

            if (pron.HasUKPronunciation)
            {
                buttonUKPron.Visibility = Visibility.Visible;

                textUKPhoentic.Text = $"[{pron.UKPronunciation.PhoneticSymbol}]";
            }
            else
            {
                buttonUKPron.Visibility = Visibility.Collapsed;
            }

            if (pron.HasUSPronunciation)
            {
                buttonUSPron.Visibility = Visibility.Visible;
                textUSPhoentic.Text     = $"[{pron.USPronunciation.PhoneticSymbol}]";
            }
            else
            {
                buttonUSPron.Visibility = Visibility.Collapsed;
            }

            panelDefinitions.Children.Clear();
            Grid definitionBlock;

            foreach (WordDefinition definition in wordResult.Definitions)
            {
                definitionBlock = wordDefinitionTemplate.LoadContent() as Grid;
                (definitionBlock.FindName("textWordPosition") as TextBlock).Text = definition.Position;
                (definitionBlock.FindName("textWordDefinition") as Run).Text     = definition.Definition;
                panelDefinitions.Children.Add(definitionBlock);
            }

            StackPanel sentenceBlock;
            Paragraph  eng, chn;

            panelSentences.Children.Clear();
            foreach (SentenceSample sentence in wordResult.Samples)
            {
                sentenceBlock = sentenceDefinitionTemplate.LoadContent() as StackPanel;
                eng           = (Paragraph)sentenceBlock.FindName("paragraphEnglish");
                chn           = (Paragraph)sentenceBlock.FindName("paragraphChinese");
                RenderSentence(word, sentence, eng, chn);
                panelSentences.Children.Add(sentenceBlock);
            }
        }
コード例 #10
0
    // when a new word is detected
    public void OnWordDetected(WordResult wordResult)
    {
        // stores word from wordResult
        var word = wordResult.Word;

        // add the new word detected to debug log
        Debug.Log("Text: New word: " + wordResult.Word.StringValue);
    }
コード例 #11
0
        public JsonResult IsWinnerResultSt(int St)
        {
            WordResult result = new WordResult {
                Result  = false,
                Message = ""
            };

            result.Result = service.IsWinnerResultSt(St);
            return(Json(result));
        }
コード例 #12
0
        public virtual void decode()
        {
            LinkedList linkedList = new LinkedList();
            int        num        = 0;

            this.hypothesisTranscript = new FileWriter(this.hypothesisFile);
            this.recognizer.allocate();
            Result result;
            List   list;

            while ((result = this.recognizer.recognize()) != null)
            {
                this.numUtterances++;
                string bestResultNoFiller = result.getBestResultNoFiller();
                [email protected](new StringBuilder().append("\nHYP: ").append(bestResultNoFiller).toString());
                [email protected](new StringBuilder().append("   Sentences: ").append(this.numUtterances).toString());
                linkedList.add(bestResultNoFiller);
                Iterator iterator = result.getTimedBestResult(false).iterator();
                while (iterator.hasNext())
                {
                    WordResult wordResult = (WordResult)iterator.next();
                    this.hypothesisTranscript.write(wordResult.toString());
                    this.hypothesisTranscript.write(32);
                }
                this.hypothesisTranscript.write(10);
                this.hypothesisTranscript.flush();
                if (this.alignInterval > 0)
                {
                    bool flag = this.numUtterances != 0;
                    int  num2 = this.alignInterval;
                    if (num2 == -1 || (flag ? 1 : 0) % num2 == 0)
                    {
                        list = this.referenceSource.getReferences();
                        List list2 = list.subList(num, list.size());
                        this.alignResults(linkedList, list2);
                        linkedList = new LinkedList();
                        num        = list.size();
                    }
                }
            }
            this.hypothesisTranscript.close();
            List references = this.referenceSource.getReferences();

            list = references.subList(num, references.size());
            if (!linkedList.isEmpty() || !list.isEmpty())
            {
                this.alignResults(linkedList, list);
            }
            [email protected]("# ------------- Summary Statistics -------------");
            this.aligner.printTotalSummary();
            this.recognizer.deallocate();
            this.showLiveSummary();
            [email protected]();
        }
コード例 #13
0
    /// <summary>
    /// This method is called whenever a new word has been detected
    /// </summary>
    /// <param name="wordResult">New trackable with current pose</param>
    public void OnWordDetected(WordResult wordResult)
    {
        var word = wordResult.Word;

        if (ContainsWord(word))
        {
            Debug.LogError("Word was already detected before!");
        }
        Debug.Log("Text: New word: " + wordResult.Word.StringValue + "(" + wordResult.Word.ID + ")");
        AddWord(wordResult);
    }
コード例 #14
0
ファイル: Solver.cs プロジェクト: bassemancoder/wordsolver
        private WordResult getNext(bool best, WordResult iReferenceWord = null)
        {
            WordResult wRetValue = null;

            lock (mOngoingResults)
            {
                var t = mOngoingResults.Except(mGivenWords);
                if (best)
                {
                    if (iReferenceWord != null)
                    {
                        //var res2 = t.OrderBy(x => LevenshteinDistance(iReferenceWord.Word, x.Value.Word)).FirstOrDefault();
                        var res2 = t.OrderByDescending(x => Scoring(iReferenceWord.Word, x.Value.Word)).FirstOrDefault();
                        if (res2.Value != null)
                        {
                            wRetValue = res2.Value;
                        }
                        var res = t.OrderByDescending(x => x.Value.Score).FirstOrDefault();
                        if (res.Value != null && res.Value.Score > (wRetValue.Score + 3))
                        {
                            wRetValue = res.Value;
                        }
                    }
                    else
                    {
                        var res = t.OrderByDescending(x => x.Value.Score).FirstOrDefault();
                        if (res.Value != null)
                        {
                            //wRetValue.Score
                            wRetValue = res.Value;
                        }
                    }
                }
                else
                {
                    var res = t.OrderBy(x => x.Value.Score).FirstOrDefault();
                    if (res.Value != null)
                    {
                        wRetValue = res.Value;
                    }
                }
            }
            if (wRetValue != null)
            {
                mGivenWords.Add(wRetValue.Word, wRetValue);
            }

            return(wRetValue);
        }
コード例 #15
0
        public IList <WordResult> Execute(IWordDictionary dictionary)
        {
            var result        = new WordResult("Using Character");
            var nospaceResult = new WordResult("Using Character (without word including space)");
            var list          = new List <WordResult>();

            if (_settings.IncludeSpace != "no")
            {
                list.Add(result);
            }

            if (_settings.IncludeSpace != "yes")
            {
                list.Add(nospaceResult);
            }

            foreach (var word in dictionary.Words)
            {
                var pairs = word.Aggregate(new Dictionary <char, int>(), (acc, x) =>
                {
                    if (acc.ContainsKey(x))
                    {
                        acc[x]++;
                    }
                    else
                    {
                        acc[x] = 1;
                    }
                    return(acc);
                });

                var nospace = !word.Any(x => char.IsWhiteSpace(x));
                foreach (var pair in pairs)
                {
                    var key = pair.Key.ToString();
                    if (_settings.IncludeSpace != "no")
                    {
                        result.AddCount(key, pair.Value);
                    }

                    if (_settings.IncludeSpace != "yes" && nospace)
                    {
                        nospaceResult.AddCount(key, pair.Value);
                    }
                }
            }

            return(list);
        }
コード例 #16
0
    private WordAbstractBehaviour AssociateWordBehaviour(WordResult wordResult, WordAbstractBehaviour wordBehaviourTemplate)
    {
        if (this.mActiveWordBehaviours.Count >= this.mMaxInstances)
        {
            return(null);
        }
        Word word = wordResult.Word;
        WordAbstractBehaviour behaviour  = wordBehaviourTemplate;
        IEditorWordBehaviour  behaviour2 = behaviour;

        behaviour2.SetNameForTrackable(word.StringValue);
        behaviour2.InitializeWord(word);
        this.mActiveWordBehaviours.Add(word.ID, behaviour);
        return(behaviour);
    }
コード例 #17
0
    /// <summary>
    /// This method is called whenever a new word has been detected
    /// </summary>
    /// <param name="wordResult">New trackable with current pose</param>
    public void OnWordDetected(WordResult wordResult)
    {
        var word = wordResult.Word;

        if (ContainsWord(word))
        {
            Debug.LogError("Word was already detected before!");
        }


        Debug.Log("Text: New word: " + wordResult.Word.StringValue + "(" + wordResult.Word.ID + ")");
        AddWord(wordResult);
        status = true;
        myWord = wordResult.Word.StringValue.ToLower();
        Debug.Log("myword is " + myWord + ".");
    }
コード例 #18
0
    /// <summary>
    /// This method is called whenever a new word has been detected
    /// </summary>
    /// <param name="wordResult">New trackable with current pose</param>
    public void OnWordDetected(WordResult wordResult)
    {
        var word = wordResult.Word;

        if (ContainsWord(word))
        {
            Debug.LogError("Word was already detected before!");
        }


        Debug.Log("Text: New word: " + wordResult.Word.StringValue + "(" + wordResult.Word.ID + ")");
        AddWord(wordResult);

        wordRequest.checkWord_LoadScene(wordResult.Word.StringValue);
        //SceneManager.LoadScene ("game");
    }
コード例 #19
0
 private void UpdateWordBehaviourPoses()
 {
     foreach (KeyValuePair <int, WordAbstractBehaviour> pair in this.mActiveWordBehaviours)
     {
         if (this.mTrackedWords.ContainsKey(pair.Key))
         {
             WordResult result      = this.mTrackedWords[pair.Key];
             Vector3    position    = result.Position;
             Quaternion orientation = result.Orientation;
             Vector2    size        = result.Word.Size;
             pair.Value.transform.rotation = orientation;
             Vector3 vector3 = (Vector3)(pair.Value.transform.rotation * new Vector3(-size.x * 0.5f, 0f, -size.y * 0.5f));
             pair.Value.transform.position = position + vector3;
             pair.Value.OnTrackerUpdate(result.CurrentStatus);
         }
     }
 }
コード例 #20
0
        public JsonResult Entry(WordEntry entry)
        {
            WordResult result = new WordResult {
                Result  = false,
                Message = ""
            };

            try {
                WordEvent wordEvent = service.EntryWord(entry, Request.ServerVariables["REMOTE_ADDR"]);
                Session["Word_Id"] = wordEvent.Id;
                result.Result      = true;
                result.Message     = "정상적으로 처리 되었습니다.";
            } catch (Exception e) {
                result.Result  = false;
                result.Message = e.Message;
            }
            return(Json(result));
        }
コード例 #21
0
        public IList <WordResult> Execute(IWordDictionary dictionary)
        {
            var length = 2;

            if (!(_settings.Length is null) && _settings.Length >= 2)
            {
                length = _settings.Length.Value;
            }

            var result        = new WordResult("Concat Character");
            var nospaceResult = new WordResult("Concat Character (without word including space)");
            var list          = new List <WordResult>();

            if (_settings.IncludeSpace != "no")
            {
                list.Add(result);
            }

            if (_settings.IncludeSpace != "yes")
            {
                list.Add(nospaceResult);
            }

            foreach (var word in dictionary.Words)
            {
                var nospace = !word.Any(x => char.IsWhiteSpace(x));

                for (int i = 0; i < (word.Length - length); i++)
                {
                    var substr = word.Substring(i, length);
                    if (_settings.IncludeSpace != "no")
                    {
                        result.CountUp(substr);
                    }

                    if (_settings.IncludeSpace != "yes" && nospace)
                    {
                        nospaceResult.CountUp(substr);
                    }
                }
            }

            return(list);
        }
コード例 #22
0
    private WordBehaviour AssociateWordBehaviour(WordResult wordResult, WordBehaviour wordBehaviourTemplate)
    {
        if (mActiveWordBehaviours.Count >= mMaxInstances)
        {
            return(null);
        }

        var word = wordResult.Word;

        var wordBehaviour = wordBehaviourTemplate;
        var ewb           = (IEditorWordBehaviour)wordBehaviour;

        ewb.SetNameForTrackable(word.StringValue);
        ewb.InitializeWord(word);

        mActiveWordBehaviours.Add(word.ID, wordBehaviour);

        return(wordBehaviour);
    }
コード例 #23
0
    /// <summary>
    /// Associate a word result with a word behaviour
    /// </summary>
    private WordBehaviour AssociateWordBehaviour(WordResult wordResult)
    {
        //find possible word prefabs based on string value of word trackable
        var stringValue = wordResult.Word.StringValue.ToLowerInvariant();
        List <WordBehaviour> wordBehaviours;

        if (mWordBehaviours.ContainsKey(stringValue))
        {
            wordBehaviours = mWordBehaviours[stringValue];
        }
        else if (mWordBehaviours.ContainsKey(TEMPLATE_IDENTIFIER))
        {
            wordBehaviours = mWordBehaviours[TEMPLATE_IDENTIFIER];
        }
        else
        {
            Debug.Log("No prefab available for string value " + stringValue);
            return(null);
        }

        //go over all existing word-behaviour in scene
        foreach (var wordBehaviour in wordBehaviours)
        {
            if (wordBehaviour.Trackable == null)
            {
                //found corresponding word-behaviour that is not already used
                return(AssociateWordBehaviour(wordResult, wordBehaviour));
            }
        }

        //no word-behaviour could be used, so we instantiate a new one
        if (wordBehaviours.Count < mMaxInstances)
        {
            var wb = InstantiateWordBehaviour(wordBehaviours.First());
            wordBehaviours.Add(wb);

            return(AssociateWordBehaviour(wordResult, wb));
        }

        //no word-behaviour available and pool of possible behaviours is full
        return(null);
    }
コード例 #24
0
        public JsonResult Share(WordShare entry)
        {
            WordResult result = new WordResult {
                Result  = false,
                Message = ""
            };

            try {
                entry.WordEventId = (int)Session["Word_Id"];
                entry.Ip          = Request.ServerVariables["REMOTE_ADDR"];
                service.ShareWord(entry);
                result.Result  = true;
                result.Message = "정상적으로 처리 되었습니다.";
            } catch (Exception) {
                result.Result  = false;
                result.Message = "쿠키가 만료 되었습니다. 페이지 새로고침 후 다시 시도해 주세요";
            }

            return(Json(result));
        }
コード例 #25
0
    private void AddWord(WordResult wordResult)
    {
        //add new word into sorted list
        var cmp = new ObbComparison();
        int i   = 0;

        while (i < mSortedWords.Count && cmp.Compare(mSortedWords[i], wordResult) < 0)
        {
            i++;
        }

        if (i < mSortedWords.Count)
        {
            mSortedWords.Insert(i, wordResult);
        }
        else
        {
            mSortedWords.Add(wordResult);
        }
    }
コード例 #26
0
        private WordResult BuildWordResult(string whole, string denominationText)
        {
            bool amountIsZero           = true;
            bool amountIsGreaterThanOne = false;
            var  triples        = ToTriplesLeastSignificantFirst(whole);
            var  triplesAsWords = new List <string>();

            for (var i = 0; i < triples.Count; i++)
            {
                var triple = triples[i];
                var number = int.Parse(triple);
                if (number > 0)
                {
                    amountIsZero = false;
                }

                if (number > 1 || (number == 1 && i > 0))
                {
                    amountIsGreaterThanOne = true;
                }

                var threeDigitNumber = ThreeDigitNumber.FromInt(number);
                triplesAsWords.Add(threeDigitNumber.ToWords());
            }

            var result = new WordResult
            {
                AmountIsZero           = amountIsZero,
                AmountIsGreaterThanOne = amountIsGreaterThanOne,
            };

            if (!amountIsZero && amountIsGreaterThanOne)
            {
                var formatter = new WordPartsFormatter();
                result.Words = formatter.Format(triplesAsWords) + " " + denominationText;
            }
            return(result);
        }
 public TokenOverlayInfo(WordResult entity)
 {
     Initialize(entity.Text, entity.BoundingBox);
 }
 public TokenOverlayInfo(WordResult entity, double width, double height)
 {
     Initialize(entity.Text, entity.BoundingBox, width, height);
 }
コード例 #29
0
        public static void main(string[] args)
        {
            [email protected]("Loading models...");
            Configuration configuration = new Configuration();

            configuration.setAcousticModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us");
            configuration.setDictionaryPath("resource:/edu/cmu/sphinx/models/en-us/cmudict-en-us.dict");
            configuration.setLanguageModelPath("resource:/edu/cmu/sphinx/models/en-us/en-us.lm.bin");
            StreamSpeechRecognizer streamSpeechRecognizer = new StreamSpeechRecognizer(configuration);
            InputStream            resourceAsStream       = ClassLiteral <TranscriberDemo> .Value.getResourceAsStream("/edu/cmu/sphinx/demo/aligner/10001-90210-01803.wav");

            resourceAsStream.skip((long)((ulong)44));
            streamSpeechRecognizer.startRecognition(resourceAsStream);
            SpeechResult result;

            while ((result = streamSpeechRecognizer.getResult()) != null)
            {
                [email protected]("Hypothesis: %s\n", new object[]
                {
                    result.getHypothesis()
                });
                [email protected]("List of recognized words and their times:");
                Iterator iterator = result.getWords().iterator();
                while (iterator.hasNext())
                {
                    WordResult wordResult = (WordResult)iterator.next();
                    [email protected](wordResult);
                }
                [email protected]("Best 3 hypothesis:");
                iterator = result.getNbest(3).iterator();
                while (iterator.hasNext())
                {
                    string text = (string)iterator.next();
                    [email protected](text);
                }
            }
            streamSpeechRecognizer.stopRecognition();
            resourceAsStream = ClassLiteral <TranscriberDemo> .Value.getResourceAsStream("/edu/cmu/sphinx/demo/aligner/10001-90210-01803.wav");

            resourceAsStream.skip((long)((ulong)44));
            Stats stats = streamSpeechRecognizer.createStats(1);

            streamSpeechRecognizer.startRecognition(resourceAsStream);
            while ((result = streamSpeechRecognizer.getResult()) != null)
            {
                stats.collect(result);
            }
            streamSpeechRecognizer.stopRecognition();
            Transform transform = stats.createTransform();

            streamSpeechRecognizer.setTransform(transform);
            resourceAsStream = ClassLiteral <TranscriberDemo> .Value.getResourceAsStream("/edu/cmu/sphinx/demo/aligner/10001-90210-01803.wav");

            resourceAsStream.skip((long)((ulong)44));
            streamSpeechRecognizer.startRecognition(resourceAsStream);
            while ((result = streamSpeechRecognizer.getResult()) != null)
            {
                [email protected]("Hypothesis: %s\n", new object[]
                {
                    result.getHypothesis()
                });
            }
            streamSpeechRecognizer.stopRecognition();
        }
コード例 #30
0
    /// <summary>
    /// This method will be called whenever a new word has been detected
    /// </summary>
    /// <param name="wordResult">New trackable with current pose</param>
    public void OnWordDetected(WordResult wordResult)
    {
        var word = wordResult.Word;
        if (ContainsWord(word))
            Debug.LogError("Word was already detected before!");

        Debug.Log("Text: New word: " + wordResult.Word.StringValue + "(" + wordResult.Word.ID + ")");
        AddWord(wordResult);
    }
コード例 #31
0
    private void AddWord(WordResult wordResult)
    {
        //add new word into sorted list
        var cmp = new ObbComparison();
        int i = 0;
        while (i < mSortedWords.Count && cmp.Compare(mSortedWords[i], wordResult) < 0)
        {
            i++;
        }

        if (i < mSortedWords.Count)
        {
            mSortedWords.Insert(i, wordResult);
        }
        else
        {
            mSortedWords.Add(wordResult);
        }
    }
コード例 #32
0
    /// <summary>
    /// Associate a word result with a word behaviour
    /// </summary>
    private WordBehaviour AssociateWordBehaviour(WordResult wordResult)
    {
        //find possible word prefabs based on string value of word trackable
        var stringValue = wordResult.Word.StringValue.ToLowerInvariant();
        List<WordBehaviour> wordBehaviours;
        if (mWordBehaviours.ContainsKey(stringValue))
            wordBehaviours = mWordBehaviours[stringValue];
        else if (mWordBehaviours.ContainsKey(TEMPLATE_IDENTIFIER))
            wordBehaviours = mWordBehaviours[TEMPLATE_IDENTIFIER];
        else
        {
            Debug.Log("No prefab available for string value " + stringValue);
            return null;
        }

        //go over all existing word-behaviour in scene
        foreach (var wordBehaviour in wordBehaviours)
        {
            if (wordBehaviour.Trackable == null)
            {
                //found corresponding word-behaviour that is not already used
                return AssociateWordBehaviour(wordResult, wordBehaviour);
            }
        }

        //no word-behaviour could be used, so we instantiate a new one
        if (wordBehaviours.Count < mMaxInstances)
        {
            var wb = InstantiateWordBehaviour(wordBehaviours.First());
            wordBehaviours.Add(wb);

            return AssociateWordBehaviour(wordResult, wb);
        }

        //no word-behaviour available and pool of possible behaviours is full
        return null;
    }
コード例 #33
0
    private WordBehaviour AssociateWordBehaviour(WordResult wordResult, WordBehaviour wordBehaviourTemplate)
    {
        if (mActiveWordBehaviours.Count >= mMaxInstances)
            return null;

        var word = wordResult.Word;

        var wordBehaviour = wordBehaviourTemplate;
        var ewb = (IEditorWordBehaviour) wordBehaviour;

        ewb.SetNameForTrackable(word.StringValue);
        ewb.InitializeWord(word);

        mActiveWordBehaviours.Add(word.ID, wordBehaviour);

        return wordBehaviour;
    }
コード例 #34
0
        private async Task <WordResult> FetchWordFromSourceAsync(String strword, WordSource wordsrc)
        {
            var client = new HttpClient();

            client.DefaultRequestHeaders.Accept.Clear();
            client.DefaultRequestHeaders.Accept.Add(
                new MediaTypeWithQualityHeaderValue("text/html"));

            //Boolean useBing = true; // https://cn.bing.com/dict/search?q=university&qs=n&form=Z9LH5&sp=-1&pq=university&sc=8-10&sk=
            //Boolean useIciba = false; // http://www.iciba.com/
            //Boolean useYoudao = false; // US pron: https://dict.youdao.com/dictvoice?audio=take+part+in&type=2
            String     resString = String.Empty;
            WordResult wr        = new WordResult();

            try
            {
                Regex regex  = new Regex(@"<[^>]*>");
                Regex regex2 = new Regex(@"</[^>]*>");

                if (wordsrc == WordSource.Bing)
                {
                    String strword2 = strword.Replace(" ", "+");
                    resString = await client.GetStringAsync("https://www.bing.com/dict/search?q=" + strword2);

                    wr.WordString = strword;

                    Int32 iPos  = resString.IndexOf("<div class=\"lf_area\">");
                    Int32 iPos2 = resString.IndexOf("<div class=\"sidebar\">");
                    if (iPos == -1 || iPos2 == -1)
                    {
                        // Error occurs
                    }
                    else
                    {
                        String strContent = resString.Substring(iPos, iPos2 - iPos);
                        iPos  = strContent.IndexOf("<div class=\"qdef\">");
                        iPos2 = strContent.IndexOf("<div class=\"se_div\">");

                        if (iPos != -1 && iPos2 != -1)
                        {
                            String strdef  = strContent.Substring(iPos, iPos2 - iPos);
                            String strsent = strContent.Substring(iPos2);

                            // Pron
                            iPos = strdef.IndexOf("hd_prUS\">");
                            if (iPos != -1)
                            {
                                iPos2         = strdef.IndexOf('<', iPos);
                                wr.WordPronUS = strdef.Substring(iPos + 9, iPos2 - iPos - 9).Replace("&#160;", "");

                                iPos              = strdef.IndexOf("https:", iPos2);
                                iPos2             = strdef.IndexOf(".mp3'", iPos);
                                wr.WordPronUSFile = strdef.Substring(iPos, iPos2 + 4 - iPos);

                                iPos = iPos2;
                            }

                            iPos = strdef.IndexOf("hd_pr\">", iPos == -1 ? 0 : iPos);
                            if (iPos != -1)
                            {
                                iPos2         = strdef.IndexOf('<', iPos);
                                wr.WordPronUK = strdef.Substring(iPos + 7, iPos2 - iPos - 7).Replace("&#160;", "");

                                iPos              = strdef.IndexOf("https:", iPos2);
                                iPos2             = strdef.IndexOf(".mp3'", iPos);
                                wr.WordPronUKFile = strdef.Substring(iPos, iPos2 + 4 - iPos);

                                iPos = iPos2;
                            }

                            // Explains
                            iPos = strdef.IndexOf("<ul>", iPos == -1 ? 0 : iPos);
                            if (iPos != -1)
                            {
                                iPos2 = strdef.IndexOf("</ul>", iPos);
                                String strexp = strdef.Substring(iPos, iPos2 - iPos);

                                iPos = strexp.IndexOf("<li>");
                                while (iPos != -1)
                                {
                                    iPos2 = strexp.IndexOf("</li>", iPos);
                                    String expit = strexp.Substring(iPos, iPos2 - iPos);
                                    expit = regex.Replace(expit, "");
                                    expit = regex2.Replace(expit, "");
                                    wr.WordExplains.Add(expit);

                                    iPos = strexp.IndexOf("<li>", iPos2);
                                }

                                iPos = iPos2;
                            }

                            // Forms
                            iPos = strdef.IndexOf("<div class=\"hd_if\">", iPos == -1 ? 0 : iPos);
                            if (iPos != -1)
                            {
                                iPos2 = strdef.IndexOf("</div>", iPos);
                                string   strform = strdef.Substring(iPos, iPos2 - iPos);
                                string[] forms   = strform.Split("&nbsp;&nbsp;");
                                foreach (var frm in forms)
                                {
                                    var frm2 = regex.Replace(frm, "");
                                    frm2 = regex2.Replace(frm2, "");
                                    frm2 = frm2.Replace("&#160;&#160;", "");

                                    if (!String.IsNullOrEmpty(frm2))
                                    {
                                        wr.WordForms.Add(frm2);
                                    }
                                }

                                iPos = iPos2;
                            }

                            // Sentences
                            iPos = strsent.IndexOf("<div id=\"sentenceSeg\">");
                            if (iPos != -1)
                            {
                                iPos = strsent.IndexOf("<div class=\"se_li\">", iPos);
                                while (iPos != -1)
                                {
                                    iPos  = strsent.IndexOf("<div class=\"sen_en\">", iPos);
                                    iPos2 = strsent.IndexOf("</div>", iPos);
                                    WordRefSent wrs = new WordRefSent();
                                    wrs.EnSent = strsent.Substring(iPos, iPos2 - iPos);
                                    wrs.EnSent = regex.Replace(wrs.EnSent, "");
                                    wrs.EnSent = regex2.Replace(wrs.EnSent, "");

                                    iPos       = strsent.IndexOf("<div class=\"sen_cn\">", iPos2);
                                    iPos2      = strsent.IndexOf("</div>", iPos);
                                    wrs.CnSent = strsent.Substring(iPos, iPos2 - iPos);
                                    wrs.CnSent = regex.Replace(wrs.CnSent, "");
                                    wrs.CnSent = regex2.Replace(wrs.CnSent, "");

                                    wr.WordSentences.Add(wrs);

                                    iPos = strsent.IndexOf("<div class=\"se_li\">", iPos2);
                                }
                            }
                        }
                    }
                }
                else if (wordsrc == WordSource.Iciba)
                {
                    // Check whether there is a SPACE inside
                    String strword2 = strword.Trim();
                    strword2  = strword2.Replace(" ", "%20");
                    resString = await client.GetStringAsync("http://www.iciba.com/" + strword2);

                    Boolean bfailed = false;
                    wr.WordString = strword;

                    // Pron.
                    Int32 iPos  = resString.IndexOf("<div class=\"base-speak\">");
                    Int32 iPos2 = -1;
                    if (iPos != -1)
                    {
                        iPos += "<div class=\"base-speak\">".Length;

                        iPos2 = resString.IndexOf("</div>", iPos);
                        String usPron = resString.Substring(iPos, iPos2 - iPos);

                        if (!String.IsNullOrEmpty(usPron))
                        {
                            iPos = usPron.IndexOf("<span>");
                            if (iPos != -1)
                            {
                                iPos += "<span>".Length;
                            }
                            if (iPos != -1)
                            {
                                usPron = usPron.Remove(0, iPos);
                                iPos   = usPron.IndexOf("<span>");

                                if (iPos != -1)
                                {
                                    iPos2 = usPron.IndexOf("</span>", iPos);

                                    wr.WordPronUK = usPron.Substring(iPos + 6, iPos2 - iPos - 6);

                                    usPron            = usPron.Remove(0, iPos2 + "</span>".Length);
                                    iPos              = usPron.IndexOf("('");
                                    iPos2             = usPron.IndexOf("')");
                                    wr.WordPronUKFile = usPron.Substring(iPos + 2, iPos2 - iPos - 2);

                                    usPron = usPron.Remove(0, iPos2 + 2);
                                    iPos   = usPron.IndexOf("<span>");
                                    usPron = usPron.Remove(0, iPos + "<span>".Length);

                                    iPos              = usPron.IndexOf("<span>");
                                    iPos2             = usPron.IndexOf("</span>");
                                    wr.WordPronUS     = usPron.Substring(iPos + 6, iPos2 - iPos - 6);
                                    usPron            = usPron.Remove(0, iPos2 + "</span>".Length);
                                    iPos              = usPron.IndexOf("('");
                                    iPos2             = usPron.IndexOf("')");
                                    wr.WordPronUSFile = usPron.Substring(iPos + 2, iPos2 - iPos - 2);
                                }
                                else
                                {
                                    wr.WordPronUS = usPron;
                                }
                            }
                        }
                        else
                        {
                            bfailed = true;
                        }
                    }

                    // Explain
                    if (!bfailed)
                    {
                        iPos = resString.IndexOf("<ul class=\"base-list switch_part\" class=\"\">");

                        if (iPos != -1)
                        {
                            iPos2 = resString.IndexOf("</ul>", iPos) + "</ul>".Length;
                            String expStr = resString.Substring(iPos, iPos2 - iPos);

                            if (!String.IsNullOrEmpty(expStr))
                            {
                                iPos = expStr.IndexOf("<li");
                                while (iPos != -1)
                                {
                                    iPos2 = expStr.IndexOf("</li>", iPos);

                                    String expitem = expStr.Substring(iPos + 3, iPos2 - iPos);
                                    Int32  j1      = expitem.IndexOf("<span");
                                    Int32  j2      = -1;
                                    String strexp  = "";
                                    while (j1 != -1)
                                    {
                                        j2      = expitem.IndexOf("</span>", j1);
                                        j1      = expitem.IndexOf(">", j1);
                                        strexp += expitem.Substring(j1 + 1, j2 - j1 - 1);

                                        j1 = expitem.IndexOf("<span", j2);
                                    }
                                    if (!String.IsNullOrEmpty(strexp))
                                    {
                                        wr.WordExplains.Add(strexp);
                                    }

                                    iPos = expStr.IndexOf("<li", iPos2);
                                }
                            }
                            else
                            {
                                bfailed = true;
                            }
                        }
                    }

                    // Transforms
                    iPos = resString.IndexOf("<h1 class=\"base-word abbr chinese change-base\">");
                    if (iPos != -1)
                    {
                        iPos  = resString.IndexOf("<p>", iPos);
                        iPos += 3;
                        iPos2 = resString.IndexOf("</p>", iPos);
                        String strForms = resString.Substring(iPos, iPos2 - iPos);

                        iPos = strForms.IndexOf("<span>");
                        while (iPos != -1)
                        {
                            iPos += 6; // "<span>".Length
                            iPos2 = strForms.IndexOf("</span>", iPos);

                            String strfi = strForms.Substring(iPos, iPos2 - iPos);
                            strfi = strfi.Trim();

                            Int32 f1 = strfi.IndexOf("<");
                            Int32 f2 = strfi.IndexOf(">", f1);
                            Int32 f3 = strfi.IndexOf("</a>", f2);
                            wr.WordForms.Add(strfi.Substring(0, f1).Trim() + " " + strfi.Substring(f2 + 1, f3 - f2 - 1).Trim());

                            iPos = strForms.IndexOf("<span>", iPos2);
                        }
                    }

                    // Sentences
                    iPos = resString.IndexOf("<div class='sentence-item'>");
                    while (iPos != -1)
                    {
                        iPos2 = resString.IndexOf("</div>", iPos);

                        String strSent = resString.Substring(iPos, iPos2 - iPos);
                        Int32  s1      = strSent.IndexOf("<p class='family-english'>");
                        s1 = strSent.IndexOf("<span>", s1);
                        Int32 s2 = strSent.IndexOf("</span>", s1);

                        WordRefSent wrs = new WordRefSent();
                        wrs.EnSent = strSent.Substring(s1 + 6, s2 - s1 - 6);
                        wrs.EnSent = wrs.EnSent.Replace("<b>", "");
                        wrs.EnSent = wrs.EnSent.Replace("</b>", "");

                        s1         = strSent.IndexOf("<p class='family-chinese size-chinese'>", s2);
                        s1        += "<p class='family-chinese size-chinese'>".Length;
                        s2         = strSent.IndexOf("</p>", s1);
                        wrs.CnSent = strSent.Substring(s1, s2 - s1);
                        wrs.CnSent = wrs.CnSent.Replace("<b>", "");
                        wrs.CnSent = wrs.CnSent.Replace("</b>", "");
                        wr.WordSentences.Add(wrs);

                        iPos = resString.IndexOf("<div class='sentence-item'>", iPos2);
                    }
                }
                else
                {
                }
            }
            catch (Exception exp)
            {
                Console.WriteLine("Error on " + strword + " : " + exp.Message);
            }

            return(wr);
        }