Пример #1
0
        void OnTestClick(object sender, EventArgs e)
        {
            String[] fname =
            {
                //"BookZero.txt",
                "Abbaye.htm",
                "Boeing.htm",
                "Edward.htm",
                "Imperial_German_Navy.htm",
                "Kosciuszko.htm",
                "Larry.htm",
                "ManualRus.htm",
                "Nebezpeci.htm",
                "Netherlands.htm",
                "Rus2.htm"
            };
            String[] lang =
            {
                //"eng",
                "fra",
                "eng",
                "eng",
                "eng",
                "pol",
                "eng",
                "rus",
                "cze",
                "eng",
                "rus"
            };
            long totalTime = 0;
            var  sw0       = new Stopwatch();

            sw0.Start();
            for (int i = 0; i < fname.Length; i++)
            {
                String text = TdApp.ConvertAssetToString(fname[i]);
                var    sw   = new Stopwatch();
                sw.Start();
                var sentences = TtsSentenceExtractor.Extract(text, lang[i]);
                sw.Stop();
                Log.Debug(TAG,
                          fname[i] + ": sentences.Count = " + sentences.Count + ", time = " + sw.ElapsedMilliseconds);
                totalTime += sw.ElapsedMilliseconds;
            }
            sw0.Stop();
            grandTotal          += totalTime;
            grandTotalWithFiles += sw0.ElapsedMilliseconds;
            numRuns++;
            Log.Debug(TAG, "----------------------------------------------------------------");
            Log.Debug(TAG, "Total time: " + totalTime + " ms" + ", with file reading total: " + sw0.ElapsedMilliseconds);
            Log.Debug(TAG, ".");
            Log.Debug(TAG, ".");
            Log.Debug(TAG, ".");
        }
        private static void InitExtractor(Locale loc)
        {
            if (loc == null)
            {
                return;
            }
            String lang = loc.ISO3Language.ToLower();

            if (lang.Equals(_lastLang))
            {
                return;
            }
            //            TextToSpeech currentTTS = SpeakService.myTTS;
            //            if (currentTTS != null) {
            //                try {
            //                    // Stupid: getCurrentEngine() of TTS is hidden. Try to get current engine if we can -
            //                    // at some point we may not be using the default TTS engine...
            //                    java.lang.reflect.Method method;
            //                    method = SpeakService.myTTS.getClass().getMethod("getCurrentEngine");
            //                    String currEngine = (String) method.invoke(currentTTS);
            //                    _breakSentences = currEngine.equals("nuance.tts");
            //                } catch (Exception e) {
            //                    _breakSentences = currentTTS.getDefaultEngine().equals("nuance.tts");
            //                }
            //            } else {
            //                _breakSentences = false;
            //            }

            _lastLang = lang;
            _abbrev   = null;
            _replace  = null;
            String abbreviations = TdApp.ConvertAssetToString("abbrev-" + lang + ".txt");

            if (abbreviations != null)
            {
                _abbrev = new Regex("\n", RegexOptions.Multiline).Split(abbreviations.Replace("\r", ""));
            }

            String replacements = TdApp.ConvertAssetToStringNoComments("replace-" + lang + ".txt");

            if (replacements != null)
            {
                String[] rpl = new Regex("\n", RegexOptions.Multiline).Split(replacements.Replace("\r", ""));
                _replace = new List <StringPair>();
                foreach (String s in rpl)
                {
                    bool   ignoreCase = true;
                    String ss         = s;
                    if (ss.StartsWith("^"))
                    {
                        ignoreCase = false;
                        ss         = ss.Substring(1).Trim();
                    }
                    int split = ss.IndexOf(" : ", StringComparison.Ordinal);
                    if (split > 0)
                    {
                        String s1 = (ignoreCase ? "(?i)" : "") + "\\Q" + ss.Substring(0, split) + "\\E";
                        String s2 = ss.Substring(split + 3);
                        _replace.Add(new StringPair(new Regex(s1, RegexOptions.None), s2));
                    }
                }
                if (_replace.Count == 0)
                {
                    _replace = null;
                }
            }
        }