| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- using System.Speech.Synthesis;
- using System.Text.RegularExpressions;
- namespace ContentEditor {
- public partial class frmMain : Form {
- public static Leah.Speech.text.Contents Content;
- private static string currentFile = "";
- private static string currentFileName = "Unknown.bpc";
- private static string currentDirectory;
- private DataSave save;
- public static bool bNeedAutoSave = false;
- private DateTime autosaveTime;
- private bool inUpdateMode = false;
- public static SpeechSynthesizer Speech = new SpeechSynthesizer();
- public static bool bIsPlaying = false;
- private static bool bIsSsml = false;
- public frmMain() {
- InitializeComponent();
- Application.ApplicationExit += Application_ApplicationExit;
- System.Diagnostics.Debug.WriteLine("UpdateMode start frmMain()");
- this.inUpdateMode = true;
- currentDirectory = System.IO.Directory.GetCurrentDirectory() + System.IO.Path.DirectorySeparatorChar;
- this.tabControl1.Selecting += TabControl1_Selecting;
- this.dgvTags.CellValueChanged += DgvTags_CellValueChanged;
- this.dgvOptionalTags.CellValueChanged += DgvOptionalTags_CellValueChanged;
- this.tvTags.AfterSelect += tvTags_AfterSelect;
- this.dgvTexts.RowsAdded += DgvTexts_RowsAdded;
- this.dgvTexts.CellEndEdit += DgvTexts_CellEndEdit;
- this.dgvTexts.UserDeletingRow += DgvTexts_UserDeletingRow;
- //this.cmdTexts_Edit.Click += new System.EventHandler(this.cmdTexts_Edit_Click);
- this.dgvTexts.CellBeginEdit += DgvTexts_CellBeginEdit;
- this.dgvTags.UserDeletingRow += DgvTags_UserDeletingRow;
- this.dgvOptionalTags.UserDeletingRow += DgvOptionalTags_UserDeletingRow;
- this.dgvTags.CellEndEdit += DgvTags_CellEndEdit;
- this.dgvOptionalTags.CellEndEdit += DgvOptionalTags_CellEndEdit;
- this.mnuFile_Last_Itm1.Click += new System.EventHandler(this.mnuFile_Last_Click);
- this.mnuFile_Last_Itm2.Click += new System.EventHandler(this.mnuFile_Last_Click);
- this.mnuFile_Last_Itm3.Click += new System.EventHandler(this.mnuFile_Last_Click);
- this.mnuFile_Last_Itm4.Click += new System.EventHandler(this.mnuFile_Last_Click);
- this.mnuFile_Last_Itm5.Click += new System.EventHandler(this.mnuFile_Last_Click);
- this.mnuFile_Last_Itm6.Click += new System.EventHandler(this.mnuFile_Last_Click);
- this.mnuFile_Last_Itm7.Click += new System.EventHandler(this.mnuFile_Last_Click);
- this.mnuFile_Last_Itm8.Click += new System.EventHandler(this.mnuFile_Last_Click);
- this.mnuFile_Last_Itm9.Click += new System.EventHandler(this.mnuFile_Last_Click);
- this.mnuFile_Last_Itm10.Click += new System.EventHandler(this.mnuFile_Last_Click);
- this.mnuText2Speach_Voice_Itm1.Click += mnuText2Speach_Voice_Click;
- this.mnuText2Speach_Voice_Itm2.Click += mnuText2Speach_Voice_Click;
- this.mnuText2Speach_Voice_Itm3.Click += mnuText2Speach_Voice_Click;
- this.mnuText2Speach_Voice_Itm4.Click += mnuText2Speach_Voice_Click;
- this.mnuText2Speach_Voice_Itm5.Click += mnuText2Speach_Voice_Click;
- this.mnuText2Speach_Voice_Itm6.Click += mnuText2Speach_Voice_Click;
- this.mnuText2Speach_Voice_Itm7.Click += mnuText2Speach_Voice_Click;
- this.mnuText2Speach_Voice_Itm8.Click += mnuText2Speach_Voice_Click;
- this.mnuText2Speach_Voice_Itm9.Click += mnuText2Speach_Voice_Click;
- this.mnuText2Speach_Voice_Itm10.Click += mnuText2Speach_Voice_Click;
- Speech.SpeakStarted += Speech_SpeakStarted;
- Speech.SpeakCompleted += Speech_SpeakCompleted;
- Speech.SelectVoiceByHints(VoiceGender.Female);
- RefreshVoiceList();
- this.dgvTexts.CellMouseDown += DgvTexts_CellMouseDown;
- System.Diagnostics.Debug.WriteLine("UpdateMode end frmMain()");
- this.inUpdateMode = false;
- if (File.Exists("settings.cfg")) {
- this.save = System.Fire.Serialize.Serializer.DeserializeObject<DataSave>("settings.cfg", System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8);
- this.RefreshLastFile();
- frmMain.currentDirectory = this.save.currentFolderDir;
- this.Size = this.save.windowSize;
- if (string.IsNullOrEmpty(this.save.autosave) || !File.Exists(this.save.autosave)) {
- FileNew();
- } else {
- frmMain.Content = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(this.save.autosave, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8);
- }
- } else {
- this.save = new DataSave();
- this.save.lastTab = 0;
- FileNew();
- }
- System.Diagnostics.Debug.WriteLine(
- System.Speech.SpeechFormat.Format(
- "Um 18:45h schoss der FCK sein 1:0 gegen Bayern"
- )
- );
- frmMain.bNeedAutoSave = false;
- this.SelectTab(this.save.lastTab);
- }
- private void mnuText2Speach_Voice_Click(object sender, EventArgs e) {
- string VoiceName = "";
- if((ToolStripMenuItem)sender != null) {
- Speech.SelectVoice(((ToolStripMenuItem)sender).Tag.ToString());
- }
- }
- private void Speech_SpeakCompleted(object sender, SpeakCompletedEventArgs e) {
- bIsPlaying = false;
- }
- private void Speech_SpeakStarted(object sender, SpeakStartedEventArgs e) {
- bIsPlaying = true;
- }
- private void DgvOptionalTags_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
- frmMain.bNeedAutoSave = true;
- }
- private void DgvTags_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
- frmMain.bNeedAutoSave = true;
- }
- private bool SetLastFileMenuItem(string path, ToolStripMenuItem mnu = null) {
- if(mnu==null) {
- if (mnuFile_Last_Itm1.Tag == null)
- mnu = mnuFile_Last_Itm1;
- if (mnuFile_Last_Itm2.Tag == null)
- mnu = mnuFile_Last_Itm2;
- if (mnuFile_Last_Itm3.Tag == null)
- mnu = mnuFile_Last_Itm3;
- if (mnuFile_Last_Itm4.Tag == null)
- mnu = mnuFile_Last_Itm4;
- if (mnuFile_Last_Itm5.Tag == null)
- mnu = mnuFile_Last_Itm5;
- if (mnuFile_Last_Itm6.Tag == null)
- mnu = mnuFile_Last_Itm6;
- if (mnuFile_Last_Itm7.Tag == null)
- mnu = mnuFile_Last_Itm7;
- if (mnuFile_Last_Itm8.Tag == null)
- mnu = mnuFile_Last_Itm8;
- if (mnuFile_Last_Itm9.Tag == null)
- mnu = mnuFile_Last_Itm9;
- if (mnuFile_Last_Itm10.Tag == null)
- mnu = mnuFile_Last_Itm10;
- }
- if(string.IsNullOrEmpty(path)) {
- mnu.Tag = null;
- mnu.Text = "";
- mnu.Visible = false;
- return false;
- }
- FileInfo fi = new FileInfo(path);
- if (fi.Exists) {
- mnu.Tag = path;
- mnu.Visible = true;
- mnu.Text = fi.Name;
- return true;
- } else {
- mnu.Tag = null;
- mnu.Text = "";
- mnu.Visible = false;
- }
- return false;
- }
- private void DoAutosave() {
- System.Diagnostics.Debug.WriteLine("Check Autosave()");
- double sec = (DateTime.Now - this.autosaveTime).TotalSeconds;
- if (frmMain.bNeedAutoSave == false || sec < 20) {
- System.Diagnostics.Debug.WriteLine("- Abort: " + (frmMain.bNeedAutoSave?"True":"False") + "; " + sec.ToString());
- return;
- }
- frmMain.bNeedAutoSave = false;
- string file = "autosave.bak";
- this.save.autosave = file;
- System.Diagnostics.Debug.WriteLine("- Autosave: " + file);
- System.Fire.Serialize.Serializer.SerializeObject(file, frmMain.Content, System.Fire.Serialize.Property.ArraySize.bits_16, System.Fire.Serialize.Property.StringEncoding.UTF8);
- this.autosaveTime = DateTime.Now;
- }
- private void SetLastFile(string path) {
- if(this.save.lastFileUsed_1.ToLower() == path.ToLower()) {
- return;
- } else if(this.save.lastFileUsed_2.ToLower() == path.ToLower()) {
- this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
- this.save.lastFileUsed_1 = path;
- } else if (this.save.lastFileUsed_3.ToLower() == path.ToLower()) {
- this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
- this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
- this.save.lastFileUsed_1 = path;
- } else if (this.save.lastFileUsed_4.ToLower() == path.ToLower()) {
- this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
- this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
- this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
- this.save.lastFileUsed_1 = path;
- } else if (this.save.lastFileUsed_5.ToLower() == path.ToLower()) {
- this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
- this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
- this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
- this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
- this.save.lastFileUsed_1 = path;
- } else if (this.save.lastFileUsed_6.ToLower() == path.ToLower()) {
- this.save.lastFileUsed_6 = this.save.lastFileUsed_5;
- this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
- this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
- this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
- this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
- this.save.lastFileUsed_1 = path;
- } else if (this.save.lastFileUsed_7.ToLower() == path.ToLower()) {
- this.save.lastFileUsed_7 = this.save.lastFileUsed_6;
- this.save.lastFileUsed_6 = this.save.lastFileUsed_5;
- this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
- this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
- this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
- this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
- this.save.lastFileUsed_1 = path;
- } else if (this.save.lastFileUsed_8.ToLower() == path.ToLower()) {
- this.save.lastFileUsed_8 = this.save.lastFileUsed_7;
- this.save.lastFileUsed_7 = this.save.lastFileUsed_6;
- this.save.lastFileUsed_6 = this.save.lastFileUsed_5;
- this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
- this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
- this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
- this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
- this.save.lastFileUsed_1 = path;
- } else if (this.save.lastFileUsed_9.ToLower() == path.ToLower()) {
- this.save.lastFileUsed_9 = this.save.lastFileUsed_8;
- this.save.lastFileUsed_8 = this.save.lastFileUsed_7;
- this.save.lastFileUsed_7 = this.save.lastFileUsed_6;
- this.save.lastFileUsed_6 = this.save.lastFileUsed_5;
- this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
- this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
- this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
- this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
- this.save.lastFileUsed_1 = path;
- } else {
- this.save.lastFileUsed_10 = this.save.lastFileUsed_9;
- this.save.lastFileUsed_8 = this.save.lastFileUsed_7;
- this.save.lastFileUsed_7 = this.save.lastFileUsed_6;
- this.save.lastFileUsed_6 = this.save.lastFileUsed_5;
- this.save.lastFileUsed_5 = this.save.lastFileUsed_4;
- this.save.lastFileUsed_4 = this.save.lastFileUsed_3;
- this.save.lastFileUsed_3 = this.save.lastFileUsed_2;
- this.save.lastFileUsed_2 = this.save.lastFileUsed_1;
- this.save.lastFileUsed_1 = path;
- }
- this.RefreshLastFile();
- }
- private void RefreshLastFile() {
- this.SetLastFileMenuItem("", this.mnuFile_Last_Itm1);
- this.SetLastFileMenuItem("", this.mnuFile_Last_Itm2);
- this.SetLastFileMenuItem("", this.mnuFile_Last_Itm3);
- this.SetLastFileMenuItem("", this.mnuFile_Last_Itm4);
- this.SetLastFileMenuItem("", this.mnuFile_Last_Itm5);
- this.SetLastFileMenuItem("", this.mnuFile_Last_Itm6);
- this.SetLastFileMenuItem("", this.mnuFile_Last_Itm7);
- this.SetLastFileMenuItem("", this.mnuFile_Last_Itm8);
- this.SetLastFileMenuItem("", this.mnuFile_Last_Itm9);
- this.SetLastFileMenuItem("", this.mnuFile_Last_Itm10);
- this.SetLastFileMenuItem(this.save.lastFileUsed_1);
- this.SetLastFileMenuItem(this.save.lastFileUsed_2);
- this.SetLastFileMenuItem(this.save.lastFileUsed_3);
- this.SetLastFileMenuItem(this.save.lastFileUsed_4);
- this.SetLastFileMenuItem(this.save.lastFileUsed_5);
- this.SetLastFileMenuItem(this.save.lastFileUsed_6);
- this.SetLastFileMenuItem(this.save.lastFileUsed_7);
- this.SetLastFileMenuItem(this.save.lastFileUsed_8);
- this.SetLastFileMenuItem(this.save.lastFileUsed_9);
- this.SetLastFileMenuItem(this.save.lastFileUsed_10);
- }
- private void DgvTexts_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {
- ushort tag_id;
- if (ushort.TryParse((string)e.Row.Tag.ToString(), out tag_id)) {
- frmMain.Content.RemoveAt(tag_id);
- this.SelectTab();
- }
- }
- private void DgvOptionalTags_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {
- int useages = 0;
- if (this.inUpdateMode == true) {
- e.Cancel = true;
- return;
- }
- this.inUpdateMode = true;
- Leah.Speech.text.ContentUseage[] use = frmMain.Content.TagUseage;
- ushort tag_id;
- if (e.Row.Tag == null) {
- tag_id=(ushort)dgvOptionalTags.Rows.IndexOf(e.Row);
- } else {
- if (!ushort.TryParse((string)e.Row.Tag.ToString(), out tag_id)) {
- return;
- }
- }
- if (useages > 0) {
- if (MessageBox.Show("The selected tag \"" + e.Row.Cells[0].Value.ToString() + "\" is used by " + useages.ToString() + " entries.\nDelete the Tag?", "Delete Optional Tags", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) {
- this.inUpdateMode = false;
- e.Cancel = true;
- return;
- }
- }
- frmMain.Content.OptionalTag_RemoveAt(tag_id);
- frmMain.bNeedAutoSave = true;
- this.inUpdateMode = false;
- }
- private void DgvTags_UserDeletingRow(object sender, DataGridViewRowCancelEventArgs e) {
- int useages = 0;
- if (this.inUpdateMode == true) {
- e.Cancel = true;
- return;
- }
- this.inUpdateMode = true;
- Leah.Speech.text.ContentUseage[] use = frmMain.Content.TagUseage;
- ushort tag_id;
- if (e.Row.Tag == null) {
- tag_id = (ushort)dgvTags.Rows.IndexOf(e.Row);
- } else {
- if (!ushort.TryParse((string)e.Row.Tag.ToString(), out tag_id)) {
- return;
- }
- }
- useages = use[tag_id].Count;
- if (useages > 0) {
- if (MessageBox.Show("The selected tag \""+e.Row.Cells[0].Value.ToString()+"\" is used by " + useages.ToString() + " entries.\nDelete the Tag?", "Delete Tags", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) {
- this.inUpdateMode = false;
- e.Cancel = true;
- return;
- }
- }
- frmMain.Content.Tag_RemoveAt(tag_id);
- frmMain.bNeedAutoSave = true;
- this.inUpdateMode = false;
- }
- private void DgvTexts_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e) {
- if (this.tvTags.SelectedNode == null || this.tvTags.SelectedNode.Tag == null) {
- e.Cancel = true;
- return;
- }
- }
- private int selectedRow = -1;
- private void DgvTexts_CellMouseDown(object sender, DataGridViewCellMouseEventArgs e) {
- if(e.Button == MouseButtons.Right) {
- if (e.RowIndex < 0) {
- // Tabellen Header
- } else if (e.ColumnIndex < 0) {
- // Zeilennummer
- } else {
- this.selectedRow = e.RowIndex;
- int pos = 0;
- foreach (DataGridViewColumn col in dgvTexts.Columns)
- if (col.Index < e.ColumnIndex)
- pos += col.Width;
- Point p = new Point(e.Location.X + dgvTexts.RowHeadersWidth + pos, e.Location.Y + (22 * e.RowIndex) + 23);
- this.cmsTexts.Show(this.dgvTexts.PointToScreen(p));
- }
- }
- }
-
- private void DgvTexts_CellEndEdit(object sender, DataGridViewCellEventArgs e) {
- System.Diagnostics.Debug.WriteLine("End edit: " + e.RowIndex);
- System.Diagnostics.Debug.WriteLine("UpdateMode start DgvTexts_CellEndEdit()");
- this.inUpdateMode = true;
- if (e.ColumnIndex==1) {
- if (dgvTexts.Rows[e.RowIndex].Cells[1].Value == null || dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == "")
- dgvTexts.Rows[e.RowIndex].Cells[1].Value = "all";
- }
- if ((dgvTexts.Rows[e.RowIndex].Cells[2].Value == null || dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value == "") && dgvTexts.Rows[e.RowIndex].Cells[0].Value != null && dgvTexts.Rows[e.RowIndex].Cells[0].Value != "") {
- dgvTexts.Rows[e.RowIndex].Cells[2].ErrorText = "At least one tag must be enterd";
- System.Diagnostics.Debug.WriteLine("- Error: At least one tag must be enterd");
- } else {
- dgvTexts.Rows[e.RowIndex].Cells[2].ErrorText = "";
- }
- Leah.Speech.text.ContentEntry entry;
- if(dgvTexts.Rows[e.RowIndex].Tag==null) {
- dgvTexts.Rows[e.RowIndex].Tag = Content.Count;
- System.Diagnostics.Debug.WriteLine("- New row added. Row: '" + dgvTexts.Rows[e.RowIndex].Tag.ToString() + "'");
- Content.Add(
- new Leah.Speech.text.ContentEntry(
- dgvTexts.Rows[e.RowIndex].Cells[0].Value==null?"":dgvTexts.Rows[e.RowIndex].Cells[0].Value.ToString(),
- Leah.Speech.text.Contents.GetMood(dgvTexts.Rows[e.RowIndex].Cells[1].Value.ToString()),
- this.GetUShortArray(dgvTexts.Rows[e.RowIndex].Cells[2].Value.ToString())
- )
- );
- }
- entry = Content.GetEntry((int)dgvTexts.Rows[e.RowIndex].Tag);
- //if (entry != null && dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) {
- if (dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value != null) {
- if (e.ColumnIndex == 0) {
- //entry.Text = dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString().Trim();
- Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Text = dgvTexts.Rows[e.RowIndex].Cells[0].Value.ToString().Trim();
- dgvTexts.Rows[e.RowIndex].Cells[0].Value = Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Text;
- System.Diagnostics.Debug.WriteLine("- Text changed: " + Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Text);
- } else if (e.ColumnIndex == 1) {
- //entry.MoodText = dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString();
- //dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value = entry.MoodText;
- Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].MoodText = dgvTexts.Rows[e.RowIndex].Cells[1].Value.ToString().Trim();
- dgvTexts.Rows[e.RowIndex].Cells[1].Value = Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].MoodText;
- System.Diagnostics.Debug.WriteLine("- Mood changed: " + Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].MoodText);
- } else if(e.ColumnIndex == 2) {
- System.Diagnostics.Debug.WriteLine("- Tag changed: " + dgvTexts.Rows[e.RowIndex].Cells[2].Value.ToString());
- Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Tag_Clear();
- Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Tag_Add(dgvTexts.Rows[e.RowIndex].Cells[2].Value.ToString());
- string rtag = "";
- foreach (ushort ustag in Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].Tags)
- rtag += (rtag == "" ? "" : ", ") + ustag.ToString();
- dgvTexts.Rows[e.RowIndex].Cells[2].Value = rtag;
- } else if (e.ColumnIndex == 3) {
- System.Diagnostics.Debug.WriteLine("- Optional Tag changed: " + dgvTexts.Rows[e.RowIndex].Cells[3].Value.ToString());
- Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].OptionalTag_Clear();
- Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].OptionalTag_Add(dgvTexts.Rows[e.RowIndex].Cells[3].Value.ToString());
- string rtag = "";
- foreach (ushort ustag in Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag].OptionalTags)
- rtag += (rtag==""?"":", ") + ustag.ToString();
- dgvTexts.Rows[e.RowIndex].Cells[3].Value = rtag;
- } else if (e.ColumnIndex == 4) {
- float s = entry.Score;
- if(float.TryParse(dgvTexts.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(), out s)) {
- entry.Score = s;
- System.Diagnostics.Debug.WriteLine("- Score changed: " + s.ToString());
- dgvTexts.Rows[e.RowIndex].Cells[4].Value = s.ToString("#,00");
- } else {
- System.Diagnostics.Debug.WriteLine("- Failed changing score. Not a number: " + dgvTexts.Rows[e.RowIndex].Cells[4].Value.ToString());
- dgvTexts.Rows[e.RowIndex].Cells[4].Value = entry.Score;
- }
- }
- } else {
- System.Diagnostics.Debug.WriteLine("- Error: No row tag");
- }
- System.Diagnostics.Debug.WriteLine("- Total Content count: "+Content.Count);
- System.Diagnostics.Debug.WriteLine("UpdateMode end DgvTexts_CellEndEdit()");
- this.inUpdateMode = false;
- frmMain.bNeedAutoSave = true;
- //Content.Entries[(int)dgvTexts.Rows[e.RowIndex].Tag] = entry;
- }
- private ushort[] GetUShortArray(string s) {
- string[] x = s.Split(new char[] { ',',';','|' });
- List<ushort> res = new List<ushort>();
- foreach (string y in x) {
- string z = y.Trim();
- ushort itm = 0;
- if(ushort.TryParse(z,out itm)) {
- res.Add(itm);
- }
- }
- return res.ToArray();
- }
- private void DgvTexts_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e) {
- for(int i=e.RowIndex, c = e.RowIndex+e.RowCount;i<c;i++) {
- dgvTexts.Rows[i].Cells[1].Value = "any";
- dgvTexts.Rows[i].Cells[2].Value = tvTags.SelectedNode.Tag;
- dgvTexts.Rows[i].Cells[3].Value = "";
- dgvTexts.Rows[i].Cells[4].Value = "0.0";
- }
- }
- private void TabControl1_Selecting(object sender, System.Windows.Forms.TabControlCancelEventArgs e) {
- this.SelectTab(e.TabPageIndex);
- }
- private void SelectTab() {
- this.SelectTab(this.tabControl1.SelectedIndex);
- }
- private void SelectTab(int index) {
- System.Diagnostics.Debug.WriteLine("UpdateMode start SelectTab()");
- this.inUpdateMode = true;
- System.Diagnostics.Debug.WriteLine("SelectTab(" + index.ToString() + ")");
- this.mnuView_TagOverview.Checked = false;
- this.mnuOptionalTags.Checked = false;
- this.mnuView_General.Checked = false;
- this.save.lastTab = index;
- this.DoAutosave();
- if (this.tabControl1.SelectedIndex == index) {
- switch(index) {
- case 0:
- this.mnuView_General.Checked = true;
- break;
- case 1:
- this.mnuView_TagOverview.Checked = true;
- System.Diagnostics.Debug.WriteLine("dgvTags.Clear()");
- dgvTags.Rows.Clear();
- System.Diagnostics.Debug.WriteLine("dgvOptionalTags.Clear()");
- dgvOptionalTags.Rows.Clear();
- System.Diagnostics.Debug.WriteLine("Try to fill");
- int i = 0;
- if (Content!=null) {
- foreach(Leah.Speech.text.ContentUseage tag in Content.TagUseage) {
- System.Diagnostics.Debug.WriteLine("Add Tag: "+tag.Tag);
- DataGridViewRow row = new DataGridViewRow();
- row.Tag = i;
- row.Cells.Add(new DataGridViewTextBoxCell() { Value = tag.Tag });
- row.Cells.Add(new DataGridViewTextBoxCell() { Value = tag.Count });
- dgvTags.Rows.Add(row);
- i++;
- }
- i = 0;
- foreach (Leah.Speech.text.ContentUseage tag in Content.OptionalTagUseage) {
- System.Diagnostics.Debug.WriteLine("Add OptionalTag: " + tag.Tag);
- DataGridViewRow row = new DataGridViewRow();
- row.Tag = i;
- row.Cells.Add(new DataGridViewTextBoxCell() { Value = tag.Tag });
- row.Cells.Add(new DataGridViewTextBoxCell() { Value = tag.Count });
- dgvOptionalTags.Rows.Add(row);
- i++;
- }
- } else {
- System.Diagnostics.Debug.WriteLine("No Content found");
- }
- break;
- case 2:
- this.mnuOptionalTags.Checked = true;
- List<TreeNode> childs = new List<TreeNode>();
- foreach (Leah.Speech.text.ContentUseage tag in Content.TagUseage) {
- TreeNode node = new TreeNode();
- node.Text = tag.Tag;
- node.Tag = tag.ID;
- childs.Add(node);
- }
- TreeNode tnRoot = new TreeNode("Root", childs.ToArray());
- tnRoot.Text = "Root";
- tvTags.BeginUpdate();
- tvTags.Nodes.Clear();
- tvTags.Nodes.Add(tnRoot);
- tvTags.ExpandAll();
- tvTags.EndUpdate();
- break;
- }
- } else {
- this.tabControl1.SelectedIndex = index;
- }
- System.Diagnostics.Debug.WriteLine("UpdateMode end SelectTab()");
- this.inUpdateMode = false;
- }
- private void DgvTags_CellValueChanged(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) {
- this.StoreTags();
- }
- private void DgvOptionalTags_CellValueChanged(object sender, System.Windows.Forms.DataGridViewCellEventArgs e) {
- this.StoreOptionalTags();
- }
-
- private void StoreTags() {
- if (Content == null)
- return;
- System.Diagnostics.Debug.WriteLine("StoreTags()");
- List<string> res = new List<string>();
- for (int i = 0, c = dgvTags.Rows.Count; i < c; i++) {
- if (dgvTags.Rows[i].Cells[0].Value != null && dgvTags.Rows[i].Cells[0].Value.ToString()!="") {
- res.Add(dgvTags.Rows[i].Cells[0].Value.ToString());
- }
- }
- Content.Tags = res.ToArray();
- }
- private void StoreOptionalTags() {
- if (Content == null) return;
- System.Diagnostics.Debug.WriteLine("StoreOptionalTags()");
- List<string> res = new List<string>();
- for (int i = 0, c = dgvOptionalTags.Rows.Count; i < c; i++) {
- if (dgvOptionalTags.Rows[i].Cells[0].Value != null && dgvOptionalTags.Rows[i].Cells[0].Value.ToString() != "") {
- res.Add(dgvOptionalTags.Rows[i].Cells[0].Value.ToString());
- }
- }
- Content.OptionalTags = res.ToArray();
- }
- private void FileNew() {
- this.FileNew("");
- }
- private void FileNew(string newName) {
- currentFileName = newName;
- currentFile = currentDirectory + newName;
- Content = new Leah.Speech.text.Contents();
- this.SelectTab();
- }
- private void FileLoad(string path) {
- FileLoad(new FileInfo(path));
- }
- private void FileLoad(FileInfo path) {
- if (path.Exists) {
- currentDirectory = path.Directory.FullName;
- currentFile = path.FullName;
- currentFileName = path.Name;
- Content = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(path.FullName);
- this.SelectTab();
- }
- }
- private void tvTags_AfterSelect(object sender, TreeViewEventArgs e) {
- System.Diagnostics.Debug.WriteLine("Load Text-Category entries");
- dgvTexts.Rows.Clear();
- if(e.Node.Tag!=null) {
- ushort tag = ushort.Parse(e.Node.Tag.ToString());
- for(int i=0,c=Content.Count;i<c;i++) {
- Leah.Speech.text.ContentEntry txt = Content.GetEntry(i);
- if (txt.Tag_Has(tag)) {
- DataGridViewRow row = new DataGridViewRow();
- row.Tag = i;
- row.Cells.AddRange(
- new DataGridViewTextBoxCell() { Value = txt.Text },
- new DataGridViewTextBoxCell() { Value = txt.MoodText },
- new DataGridViewTextBoxCell() { Value = String.Join(", ", txt.Tags_String) },
- new DataGridViewTextBoxCell() { Value = String.Join(", ", txt.OptionalTags_String) }
- );
- dgvTexts.Rows.Add(row);
- }
- }
- } else {
- System.Diagnostics.Debug.WriteLine("- No tag");
- }
- }
- private void cmdTexts_Edit_Click(object sender, EventArgs e) {
- Leah.Speech.text.ContentEntry res = null;
- if (this.selectedRow >= 0 && this.dgvTexts.Rows[this.selectedRow].Tag != null) {
- System.Diagnostics.Debug.WriteLine("Edit item");
- res = frmContentEdit.EditItem((int)(this.dgvTexts.Rows[this.selectedRow].Tag));
- } else {
- System.Diagnostics.Debug.WriteLine("New item");
- res = frmContentEdit.NewItem();
- }
- }
- private void mnuFile_New_Click(object sender, EventArgs e) {
- frmMain.Content = new Leah.Speech.text.Contents();
- this.SelectTab();
- }
- private void mnuFile_Open_Click(object sender, EventArgs e) {
- openFileDialog1.Title = "Open Content File";
- openFileDialog1.Filter = "Content File (*.bpc)|*.bpc|All files (*.*)|*.*";
- openFileDialog1.Multiselect = false;
- openFileDialog1.InitialDirectory = frmMain.currentDirectory;
- if(openFileDialog1.ShowDialog() == DialogResult.OK) {
- FileInfo fi = new FileInfo(openFileDialog1.FileName);
- frmMain.currentFile = fi.FullName;
- frmMain.currentFileName = fi.Name;
- frmMain.currentDirectory = fi.Directory.FullName;
- frmMain.Content = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(
- openFileDialog1.FileName,
- System.Fire.Serialize.Property.ArraySize.bits_16,
- System.Fire.Serialize.Property.StringEncoding.UTF8
- );
- this.save.currentFolderDir = frmMain.currentDirectory;
- this.SetLastFile(fi.FullName);
- this.SelectTab();
- }
- }
- private void mnuFile_Save_Click(object sender, EventArgs e) {
- if(frmMain.currentFileName.Length==0) {
- mnuFile_SaveAs_Click(sender, e);
- } else {
- System.Fire.Serialize.Serializer.SerializeObject(
- frmMain.currentFile,
- frmMain.Content,
- System.Fire.Serialize.Property.ArraySize.bits_16,
- System.Fire.Serialize.Property.StringEncoding.UTF8
- );
- this.save.currentFolderDir = frmMain.currentDirectory;
- this.SetLastFile(frmMain.currentFile);
- }
- }
- private void mnuFile_SaveAs_Click(object sender, EventArgs e) {
- saveFileDialog1.Title = "Save Content File";
- saveFileDialog1.Filter = "Content File (*.bpc)|*.bpc|All files (*.*)|*.*";
- saveFileDialog1.InitialDirectory = frmMain.currentDirectory;
- saveFileDialog1.FileName = frmMain.currentFileName;
- if (saveFileDialog1.ShowDialog() == DialogResult.OK) {
- FileInfo fi = new FileInfo(saveFileDialog1.FileName);
- frmMain.currentFile = fi.FullName;
- frmMain.currentFileName = fi.Name;
- frmMain.currentDirectory = fi.Directory.FullName;
- System.Fire.Serialize.Serializer.SerializeObject(
- frmMain.currentFile,
- frmMain.Content,
- System.Fire.Serialize.Property.ArraySize.bits_16,
- System.Fire.Serialize.Property.StringEncoding.UTF8
- );
- this.save.currentFolderDir = frmMain.currentDirectory;
- this.SetLastFile(frmMain.currentFile);
- }
- }
- /*private void importTagsToolStripMenuItem_Click(object sender, EventArgs e) {
- openFileDialog1.Title = "Import Tags";
- openFileDialog1.Filter = "Textfile (*.txt)|*.txt|CSF File (*.csv)|*.csv|All files (*.*)|*.*";
- openFileDialog1.Multiselect = false;
- openFileDialog1.InitialDirectory = frmMain.currentDirectory;
- if (openFileDialog1.ShowDialog() == DialogResult.OK) {
- FileInfo fi = new FileInfo(openFileDialog1.FileName);
- using (StreamReader sr = fi.OpenText()) {
- while (sr.Peek() >= 0) {
- string line = sr.ReadLine();
-
- }
- }
- this.SelectTab();
- }
- }*/
- private void mnuTags_DeleteAll_Click(object sender, EventArgs e) {
- frmMain.Content.Tag_Clear();
- this.SelectTab();
- }
- private void mnuTags_Import_Click(object sender, EventArgs e) {
- openFileDialog1.Title = "Import Tags";
- openFileDialog1.Filter = "Textfile (*.txt)|*.txt|BlackPro Content File|*.bpc|All files (*.*)|*.*";
- openFileDialog1.Multiselect = false;
- openFileDialog1.InitialDirectory = frmMain.currentDirectory;
- if (openFileDialog1.ShowDialog() == DialogResult.OK) {
- FileInfo fi = new FileInfo(openFileDialog1.FileName);
- if (fi.Extension == ".bpc") {
- Leah.Speech.text.Contents imp = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(fi.FullName);
- foreach(string s in imp.Tags) {
- frmMain.Content.Tag_Add(s);
- }
- } else {
- using (StreamReader sr = fi.OpenText()) {
- while (sr.Peek() >= 0) {
- string line = sr.ReadLine().Trim();
- if (line.Length > 0) {
- frmMain.Content.Tag_Add(line);
- }
- }
- }
- }
- this.SelectTab();
- }
- }
- private void mnuTags_Export_Click(object sender, EventArgs e) {
- saveFileDialog1.Title = "Export Tags";
- saveFileDialog1.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*";
- saveFileDialog1.InitialDirectory = frmMain.currentDirectory;
- saveFileDialog1.FileName = "tags.txt";
- if (saveFileDialog1.ShowDialog() == DialogResult.OK) {
- FileInfo fi = new FileInfo(saveFileDialog1.FileName);
- bool bFirst = true;
- using (FileStream fs = fi.OpenWrite()) {
- foreach (DataGridViewRow row in dgvTags.Rows) {
- if (row.Cells[0].Value != null) {
- if (bFirst == false)
- fs.Write(new byte[] { 10 },0,1);
- bFirst = false;
- string s = row.Cells[0].Value.ToString();
- byte[] b = System.Text.Encoding.ASCII.GetBytes(s);
- fs.Write(b, 0, b.Length);
- }
- }
- }
- }
- }
- private void mnuOptionalTags_DeleteAll_Click(object sender, EventArgs e) {
- frmMain.Content.OptionalTag_Clear();
- this.SelectTab();
- }
- private void mnuOptionalTags_Import_Click(object sender, EventArgs e) {
- openFileDialog1.Title = "Import Optional Tags";
- openFileDialog1.Filter = "Textfile (*.txt)|*.txt|BlackPro Content File|*.bpc|All files (*.*)|*.*";
- openFileDialog1.Multiselect = false;
- openFileDialog1.InitialDirectory = frmMain.currentDirectory;
- if (openFileDialog1.ShowDialog() == DialogResult.OK) {
- FileInfo fi = new FileInfo(openFileDialog1.FileName);
- if (fi.Extension == ".bpc") {
- Leah.Speech.text.Contents imp = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(fi.FullName);
- foreach (string s in imp.OptionalTags) {
- frmMain.Content.OptionalTag_Add(s);
- }
- } else {
- using (StreamReader sr = fi.OpenText()) {
- while (sr.Peek() >= 0) {
- string line = sr.ReadLine().Trim();
- if (line.Length > 0) {
- frmMain.Content.OptionalTag_Add(line);
- }
- }
- }
- }
- this.SelectTab();
- }
- }
- private void mnuTexts_Editor_Click(object sender, EventArgs e) {
- if(tabControl1.SelectedIndex==2 && dgvTexts.SelectedRows.Count>0) {
- if(dgvTexts.SelectedRows[0].Tag!=null) {
- frmContentEdit.EditItem((int)dgvTexts.SelectedRows[0].Tag);
- } else {
- frmContentEdit.NewItem();
- }
- } else {
- frmContentEdit.NewItem();
- }
- }
- private void mnuView_General_Click(object sender, EventArgs e) {
- this.SelectTab(0);
- }
- private void mnuView_TagOverview_Click(object sender, EventArgs e) {
- this.SelectTab(1);
- }
- private void mnuView_TextOverview_Click(object sender, EventArgs e) {
- this.SelectTab(2);
- }
- private void mnuOptionalTags_Export_Click(object sender, EventArgs e) {
- saveFileDialog1.Title = "Export Optional Tags";
- saveFileDialog1.Filter = "Text file (*.txt)|*.txt|All files (*.*)|*.*";
- saveFileDialog1.InitialDirectory = frmMain.currentDirectory;
- saveFileDialog1.FileName = "optionalTags.txt";
- if (saveFileDialog1.ShowDialog() == DialogResult.OK) {
- FileInfo fi = new FileInfo(saveFileDialog1.FileName);
- bool bFirst = true;
- using (FileStream fs = fi.OpenWrite()) {
- foreach (DataGridViewRow row in dgvOptionalTags.Rows) {
- if (row.Cells[0].Value != null) {
- if (bFirst == false)
- fs.Write(new byte[] { 10 }, 0, 1);
- bFirst = false;
- string s = row.Cells[0].Value.ToString();
- byte[] b = System.Text.Encoding.ASCII.GetBytes(s);
- fs.Write(b, 0, b.Length);
- }
- }
- }
- }
- }
- private void mnuFile_Quit_Click(object sender, EventArgs e) {
- Application.Exit();
- }
- private void Application_ApplicationExit(object sender, EventArgs e) {
- this.save.windowSize = this.Size;
- System.Fire.Serialize.Serializer.SerializeObject("settings.cfg", this.save);
- }
- private void mnuFile_Last_Click(object sender, EventArgs e) {
- ToolStripMenuItem mnu = (ToolStripMenuItem)sender;
- if (mnu != null) {
- string path = (string)mnu.Tag;
- FileInfo fi = new FileInfo(path);
- if(fi.Exists) {
- frmMain.currentFile = fi.FullName;
- frmMain.currentFileName = fi.Name;
- frmMain.currentDirectory = fi.Directory.FullName;
- frmMain.Content = System.Fire.Serialize.Serializer.DeserializeObject<Leah.Speech.text.Contents>(
- openFileDialog1.FileName,
- System.Fire.Serialize.Property.ArraySize.bits_16,
- System.Fire.Serialize.Property.StringEncoding.UTF8
- );
- this.SetLastFile(fi.FullName);
- this.save.currentFolderDir = frmMain.currentDirectory;
- this.SelectTab();
- }
- }
- }
- private void tmrAutosave_Tick(object sender, EventArgs e) {
- this.DoAutosave();
- }
- private void mnuText2Speech_Play_Click(object sender, EventArgs e) {
- if(dgvTexts.SelectedRows.Count==1) {
- if(dgvTexts.SelectedRows[0].Cells.Count>0) {
- Speak(dgvTexts.SelectedRows[0].Cells[0].Value.ToString());
- }
- }
- }
-
- private void RefreshVoiceList() {
- InstalledVoice[] voices = Speech.GetInstalledVoices().ToArray();
- this.mnuText2Speach_Voice_Itm1.Visible = false;
- this.mnuText2Speach_Voice_Itm2.Visible = false;
- this.mnuText2Speach_Voice_Itm3.Visible = false;
- this.mnuText2Speach_Voice_Itm4.Visible = false;
- this.mnuText2Speach_Voice_Itm5.Visible = false;
- this.mnuText2Speach_Voice_Itm6.Visible = false;
- this.mnuText2Speach_Voice_Itm7.Visible = false;
- this.mnuText2Speach_Voice_Itm8.Visible = false;
- this.mnuText2Speach_Voice_Itm9.Visible = false;
- this.mnuText2Speach_Voice_Itm10.Visible = false;
- if (voices.Length>=1) {
- this.mnuText2Speach_Voice_Itm1.Text = getVoiceInfo(voices[0]);
- this.mnuText2Speach_Voice_Itm1.Visible = true;
- this.mnuText2Speach_Voice_Itm1.Tag = voices[0].VoiceInfo.Name;
- }
- if (voices.Length >= 2) {
- this.mnuText2Speach_Voice_Itm2.Text = getVoiceInfo(voices[1]);
- this.mnuText2Speach_Voice_Itm2.Visible = true;
- this.mnuText2Speach_Voice_Itm2.Tag = voices[1].VoiceInfo.Name;
- }
- if (voices.Length >= 3) {
- this.mnuText2Speach_Voice_Itm3.Text = getVoiceInfo(voices[2]);
- this.mnuText2Speach_Voice_Itm3.Visible = true;
- this.mnuText2Speach_Voice_Itm3.Tag = voices[2].VoiceInfo.Name;
- }
- if (voices.Length >= 4) {
- this.mnuText2Speach_Voice_Itm4.Text = getVoiceInfo(voices[3]);
- this.mnuText2Speach_Voice_Itm4.Visible = true;
- this.mnuText2Speach_Voice_Itm4.Tag = voices[3].VoiceInfo.Name;
- }
- if (voices.Length >= 5) {
- this.mnuText2Speach_Voice_Itm5.Text = getVoiceInfo(voices[4]);
- this.mnuText2Speach_Voice_Itm5.Visible = true;
- this.mnuText2Speach_Voice_Itm5.Tag = voices[4].VoiceInfo.Name;
- }
- if (voices.Length >= 6) {
- this.mnuText2Speach_Voice_Itm6.Text = getVoiceInfo(voices[5]);
- this.mnuText2Speach_Voice_Itm6.Visible = true;
- this.mnuText2Speach_Voice_Itm6.Tag = voices[5].VoiceInfo.Name;
- }
- if (voices.Length >= 7) {
- this.mnuText2Speach_Voice_Itm7.Text = getVoiceInfo(voices[6]);
- this.mnuText2Speach_Voice_Itm7.Visible = true;
- this.mnuText2Speach_Voice_Itm7.Tag = voices[6].VoiceInfo.Name;
- }
- if (voices.Length >= 8) {
- this.mnuText2Speach_Voice_Itm8.Text = getVoiceInfo(voices[7]);
- this.mnuText2Speach_Voice_Itm8.Visible = true;
- this.mnuText2Speach_Voice_Itm8.Tag = voices[7].VoiceInfo.Name;
- }
- if (voices.Length >= 9) {
- this.mnuText2Speach_Voice_Itm9.Text = getVoiceInfo(voices[8]);
- this.mnuText2Speach_Voice_Itm9.Visible = true;
- this.mnuText2Speach_Voice_Itm9.Tag = voices[8].VoiceInfo.Name;
- }
- if (voices.Length >= 10) {
- this.mnuText2Speach_Voice_Itm10.Text = getVoiceInfo(voices[9]);
- this.mnuText2Speach_Voice_Itm10.Visible = true;
- this.mnuText2Speach_Voice_Itm10.Tag = voices[9].VoiceInfo.Name;
- }
- }
- private string getVoiceInfo(InstalledVoice voice) {
- string gender = "";
- string age = "";
- string lang = "";
- if (voice.VoiceInfo.Gender == VoiceGender.Female) gender = " female";
- else if (voice.VoiceInfo.Gender == VoiceGender.Male) gender = " male";
- else if (voice.VoiceInfo.Gender == VoiceGender.Neutral) gender = " neutral";
- if (voice.VoiceInfo.Age == VoiceAge.Adult) age = " adult";
- else if (voice.VoiceInfo.Age == VoiceAge.Child) age = " child";
- else if (voice.VoiceInfo.Age == VoiceAge.Senior) age = " old";
- else if (voice.VoiceInfo.Age == VoiceAge.Teen) age = " teen";
- lang = " (" + voice.VoiceInfo.Culture.Name + ")";
- return voice.VoiceInfo.Name + age + gender + lang;
- }
- public static void Speak(string Text) {
- if (bIsPlaying) {
- Speech.SpeakAsyncCancelAll();
- }
- string text = Text;
- bIsPlaying = true;
- text = System.Speech.SpeechFormat.Format(text);
- if (bIsSsml) {
- text = Regex.Replace(text, "<.*?>", String.Empty);
- Speech.SpeakAsync(text);
- } else {
- Speech.SpeakAsync(text);
- }
- }
- private void mnuText2Speech_SSML_Click(object sender, EventArgs e) {
- mnuText2Speech_SSML.Checked = !mnuText2Speech_SSML.Checked;
- bIsSsml = mnuText2Speech_SSML.Checked;
- }
- }
- }
|