Beispiel #1
0
        //button5生成读音
        private void button5_Click(object sender, RoutedEventArgs e)
        {
            //数据库全部读出
            WordLogic[] wordList = WordLogic.FindAll();

            SpFileStream          SpFileStream = new SpFileStream();
            String                fileName;
            SpeechVoiceSpeakFlags SpFlags    = SpeechVoiceSpeakFlags.SVSFlagsAsync;
            SpeechStreamFileMode  SpFileMode = SpeechStreamFileMode.SSFMCreateForWrite;
            SpVoice               voice      = new SpVoice();

            // prepare voice
            SpObjectTokenCategory aotc = new SpObjectTokenCategory();

            aotc.SetId(SpeechLib.SpeechStringConstants.SpeechCategoryVoices);

            foreach (ISpeechObjectToken token in aotc.EnumerateTokens())
            {
                if (token.GetDescription() == "VW Julie")
                {
                    englishToken = (SpObjectToken)token;
                }
                else if (token.GetDescription() == "VW Hui")
                {
                    chineseToken = (SpObjectToken)token;
                }
            }

            voice.Voice = englishToken;
            voice.Rate  = -4;

            String outFolderPath = Directory.GetParent("../../TestCases/") + @"\单词音频\";

            if (!Directory.Exists(outFolderPath))
            {
                Directory.CreateDirectory(outFolderPath);
            }

            for (int i = 0; i < wordList.Length; i++)
            {
                String word = wordList[i].word;

                if (word != null)
                {
                    word = word.Trim();
                }

                if (String.IsNullOrEmpty(word))
                {
                    // 遇到无效内容,退出
                    continue;
                }
                word = convert(word);

                fileName = outFolderPath + word + ".wav";
                SpFileStream.Open(fileName, SpFileMode, false);
                voice.AudioOutputStream = SpFileStream;
                voice.Speak(word, SpFlags);
                voice.WaitUntilDone(Timeout.Infinite);
                SpFileStream.Close();
            }


            MessageBox.Show("音频生成完毕!");
        }
Beispiel #2
0
        private void button1_Click(object sender, RoutedEventArgs e)
        {
            //所有sheet页循环
            for (int i = 1; i <= ewb.Sheets.Count; i++)
            {
                Worksheet subTableSheet = ewb.Sheets[i] as Worksheet;
                string    tempSheetName = subTableSheet.Name;
                if (tempSheetName.Contains("所有单词RES") ||
                    tempSheetName.Contains("所有单词logic") ||
                    tempSheetName.Contains("读音唯一")
                    )
                {
                    continue;
                }
                Dictionary <String, ArrayList> subTableWholeWordList = new Dictionary <string, ArrayList>();
                //检查字体
                int subTableSheetValidCount = GetValidCellRowCount(subTableSheet, subTableWholeWordList);
                for (int j = 2; j < subTableSheetValidCount; j++)
                {
                    String x;
                    try
                    {
                        x = ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 4])).Font.Name;
                    }
                    catch
                    {
                        x = "Kingsoft Phonetic Plain";
                    }
                    //映射字体
                    ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 8])).Value = FontName(x);

                    try
                    {
                        //插入RES
                        WordRES wordres = new WordRES();
                        //wordres.num = j;
                        wordres.word = ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 2])).Value;

                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 3])).Value))
                        {
                            wordres.subject = (int)(((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 3])).Value);
                        }

                        wordres.phoneticSymbol = ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 4])).Value;
                        wordres.wordMeaning    = ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 5])).Value;
                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 6])).Value))
                        {
                            wordres.unit = (int)((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 6])).Value;
                        }

                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 7])).Value))
                        {
                            wordres.book = (int)(((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 7])).Value) - 1;
                        }

                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 8])).Value))
                        {
                            wordres.fontType = (int)((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 8])).Value;
                        }

                        wordres.CreateAndFlush();

                        //插入Logic
                        WordLogic wordlogic = new WordLogic();
                        //wordlogic.num = j - 1;
                        wordlogic.word = ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 2])).Value;

                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 3])).Value))
                        {
                            wordlogic.subject = (int)((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 3])).Value;
                        }
                        wordlogic.remCount    = 1;
                        wordlogic.lastRemTime = new DateTime(2014, 7, 8, 18, 6, 0);
                        wordlogic.nextRemTime = new DateTime(2014, 7, 8, 18, 6, 0);

                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 6])).Value))
                        {
                            wordlogic.unit = (int)((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 6])).Value;
                        }
                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 7])).Value))
                        {
                            wordlogic.book = (int)(((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 7])).Value) - 1;
                        }

                        wordlogic.CreateAndFlush();
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc);
                    }
                }
            }
        }
Beispiel #3
0
        //button4,将各个子sheet页的内容插入到RES和Logic表中,并填入其他所缺的内容
        private void insert_words_to_list(object sender, RoutedEventArgs e)
        {
            Regex pathrgx = new Regex(@".*\\(.*\..*)");

            if (String.IsNullOrEmpty(mappath.Text))
            {
                MessageBox.Show("检查文档不能为空!");
                return;
            }

            Match parentTableMth = pathrgx.Match(mappath.Text);

            m_Workbooks.Open(mappath.Text);
            String parentWorkbookName = parentTableMth.Groups[1].ToString();

            parentWorkBook = m_Workbooks[parentWorkbookName];
            string parentWordTableName = parentWorkBook.FullName;

            Regex versionRgx = new Regex(@"([0-9]+)_(.*)");


            //所有sheet页循环
            for (int i = 1; i <= parentWorkBook.Sheets.Count; i++)
            {
                Worksheet subTableSheet = parentWorkBook.Sheets[i] as Worksheet;
                //特殊名称的sheet页跳过
                string tempSheetName = subTableSheet.Name;
                if (tempSheetName.Contains("所有单词RES") ||
                    tempSheetName.Contains("所有单词logic") ||
                    tempSheetName.Contains("读音唯一") ||
                    tempSheetName.Contains("_未分节")
                    )
                {
                    continue;
                }

                //解析版本序号名
                Match versionMatch = versionRgx.Match(tempSheetName);
                int   bookId       = -1;
                int.TryParse(versionMatch.Groups[1].ToString(), out bookId);

                Dictionary <String, ArrayList> subTableWholeWordList = new Dictionary <string, ArrayList>();
                //检查字体
                int subTableSheetValidCount = GetValidCellRowCount(subTableSheet, subTableWholeWordList);
                for (int j = 2; j < subTableSheetValidCount; j++)
                {
                    String x;
                    try
                    {
                        x = ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 4])).Font.Name;
                    }
                    catch
                    {
                        x = "Kingsoft Phonetic Plain";
                    }
                    //映射字体
                    ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 8])).Value = FontName(x);

                    try
                    {
                        //插入RES
                        WordRES wordres = new WordRES();
                        //wordres.num = j;
                        wordres.word = ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 2])).Value;

                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 3])).Value))
                        {
                            wordres.subject = (int)(((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 3])).Value);
                        }

                        wordres.phoneticSymbol = ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 4])).Value;
                        wordres.wordMeaning    = ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 5])).Value;
                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 6])).Value))
                        {
                            wordres.unit = (int)((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 6])).Value;
                        }

                        //书号
                        wordres.book = bookId - 1;

                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 8])).Value))
                        {
                            wordres.fontType = (int)((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 8])).Value;
                        }

                        wordres.CreateAndFlush();

                        //插入Logic
                        WordLogic wordlogic = new WordLogic();
                        //wordlogic.num = j - 1;
                        wordlogic.word = ((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 2])).Value;

                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 3])).Value))
                        {
                            wordlogic.subject = (int)((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 3])).Value;
                        }
                        wordlogic.remCount    = 1;
                        wordlogic.lastRemTime = new DateTime(2014, 7, 8, 18, 6, 0);
                        wordlogic.nextRemTime = new DateTime(2014, 7, 8, 18, 6, 0);

                        if (null != (((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 6])).Value))
                        {
                            wordlogic.unit = (int)((Microsoft.Office.Interop.Excel.Range)(subTableSheet.Cells[j, 6])).Value;
                        }
                        //书号
                        wordlogic.book = bookId - 1;

                        wordlogic.CreateAndFlush();
                    }
                    catch (Exception exc)
                    {
                        Console.WriteLine(exc);
                    }
                }
            }

            parentWorkBook.Save();
            MessageBox.Show("单词对应完毕!");
        }