⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 speechui.cs

📁 sound recorder in vb
💻 CS
📖 第 1 页 / 共 2 页
字号:
			this.recognition_checkbox.Name = "recognition_checkbox";
			this.recognition_checkbox.Size = new System.Drawing.Size(163, 20);
			this.recognition_checkbox.TabIndex = 1;
			this.recognition_checkbox.Text = "Enable Speech Recognition";
			this.recognition_checkbox.CheckedChanged += new System.EventHandler(this.recognition_checkbox_CheckedChanged);
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(8, 8);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(152, 16);
			this.label1.TabIndex = 0;
			this.label1.Text = "Stock Quote Results";
			// 
			// panel2
			// 
			this.panel2.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 
				| System.Windows.Forms.AnchorStyles.Right)));
			this.panel2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.panel2.Controls.Add(this.label2);
			this.panel2.Controls.Add(this.button1);
			this.panel2.Controls.Add(this.panel3);
			this.panel2.Controls.Add(this.speak_button);
			this.panel2.Controls.Add(this.label3);
			this.panel2.Controls.Add(this.exit_button);
			this.panel2.Location = new System.Drawing.Point(8, 214);
			this.panel2.Name = "panel2";
			this.panel2.Size = new System.Drawing.Size(629, 205);
			this.panel2.TabIndex = 1;
			this.panel2.Paint += new System.Windows.Forms.PaintEventHandler(this.panel2_Paint);
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(10, 161);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(607, 38);
			this.label2.TabIndex = 8;
			this.label2.Text = "INSTRUCTIONS: Spell stock symbol or say company name to hear quote. Say \"Clear\" t" +
				"o clear text box.";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(77, 2);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(55, 26);
			this.button1.TabIndex = 7;
			this.button1.Text = "Clear";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// panel3
			// 
			this.panel3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.panel3.BackColor = System.Drawing.Color.Silver;
			this.panel3.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.panel3.Controls.Add(this.label5);
			this.panel3.Controls.Add(this.voices_listbox);
			this.panel3.Controls.Add(this.label4);
			this.panel3.Controls.Add(this.rate_trackbar);
			this.panel3.Location = new System.Drawing.Point(10, 51);
			this.panel3.Name = "panel3";
			this.panel3.Size = new System.Drawing.Size(607, 97);
			this.panel3.TabIndex = 6;
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(7, 4);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(147, 14);
			this.label5.TabIndex = 11;
			this.label5.Text = "Available voices";
			// 
			// voices_listbox
			// 
			this.voices_listbox.Location = new System.Drawing.Point(7, 19);
			this.voices_listbox.Name = "voices_listbox";
			this.voices_listbox.Size = new System.Drawing.Size(195, 69);
			this.voices_listbox.TabIndex = 10;
			this.voices_listbox.SelectedIndexChanged += new System.EventHandler(this.VoiceSelected);
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(499, 22);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(87, 17);
			this.label4.TabIndex = 9;
			this.label4.Text = "Rate of Speech";
			// 
			// rate_trackbar
			// 
			this.rate_trackbar.Location = new System.Drawing.Point(488, 39);
			this.rate_trackbar.Maximum = 20;
			this.rate_trackbar.Minimum = -20;
			this.rate_trackbar.Name = "rate_trackbar";
			this.rate_trackbar.Size = new System.Drawing.Size(104, 34);
			this.rate_trackbar.TabIndex = 8;
			// 
			// speak_button
			// 
			this.speak_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.speak_button.Location = new System.Drawing.Point(7, 3);
			this.speak_button.Name = "speak_button";
			this.speak_button.Size = new System.Drawing.Size(57, 25);
			this.speak_button.TabIndex = 4;
			this.speak_button.Text = "Speak";
			this.speak_button.Click += new System.EventHandler(this.speak_button_Click);
			// 
			// label3
			// 
			this.label3.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
			this.label3.Location = new System.Drawing.Point(9, 31);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(128, 16);
			this.label3.TabIndex = 1;
			this.label3.Text = "Voice Parameter Control";
			// 
			// exit_button
			// 
			this.exit_button.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
			this.exit_button.Location = new System.Drawing.Point(140, 3);
			this.exit_button.Name = "exit_button";
			this.exit_button.Size = new System.Drawing.Size(75, 25);
			this.exit_button.TabIndex = 2;
			this.exit_button.Text = "Exit";
			this.exit_button.Click += new System.EventHandler(this.exit_button_Click);
			// 
			// SpeechUI
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.ClientSize = new System.Drawing.Size(645, 463);
			this.Controls.Add(this.panel2);
			this.Controls.Add(this.panel1);
			this.MinimumSize = new System.Drawing.Size(653, 490);
			this.Name = "SpeechUI";
			this.Text = ".NET Speech Stock Quoter";
			this.Load += new System.EventHandler(this.SpeechUI_Load);
			this.panel1.ResumeLayout(false);
			this.panel2.ResumeLayout(false);
			this.panel3.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.rate_trackbar)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		[STAThread]
		static void Main() 
		{
			Application.Run(new SpeechUI());
		}

		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if (components != null) 
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		private void exit_button_Click(object sender, System.EventArgs e)
		{
			Application.Exit();
		}
		
private string GetStockQuote (string word)
	{
	
	string path=Environment.CurrentDirectory ;
    string strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +path+ "\\" +"stocks.mdb" ;
    OleDbConnection myConn = new OleDbConnection(strConn) ;
			//Make a Select Command
         string result=String.Empty;
			try
			{
				string strCom = "Select * from Companies where name like '" + word  +"%' or symbol ='" + word + "'";
				OleDbCommand myCommand =new OleDbCommand(strCom,myConn);
				myConn.Open();
				System.Data.OleDb.OleDbDataReader reader;
				//Execute the command and get the Data into "reader"
				reader=myCommand.ExecuteReader( ) ;				
				// for now, we'll just do the first record.				
				//while(reader.Read())
				reader.Read();
			{
				result += reader.GetValue(1).ToString() + " " + GetQuote(reader.GetValue(0).ToString());	
			}		 
			}
			catch (Exception ex)

			{
				SpeakText("Sorry, Not found!");
				recognition_textbox.Clear();
			}
		 
			return   result + "\n\r";

		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			recognition_textbox.Clear();
		}

		private void panel2_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
		{
		
		}

		private void SpeechUI_Load(object sender, System.EventArgs e)
		{
			EnableSpeechRecognition();
		}


		public string GetQuote(string sSymbol)
		{
          XmlDocument xmlDoc=GetXmlYahoo(sSymbol);
		//MessageBox.Show(xmlDoc.OuterXml);		
		string  strSymbol = xmlDoc.SelectSingleNode("//StockQuotes/Quote/Symbol").InnerText ;
		string  strPrice = xmlDoc.SelectSingleNode("//StockQuotes/Quote/Price").InnerText ;
        string  strChange = xmlDoc.SelectSingleNode("//StockQuotes/Quote/Change").InnerText ;
		string strTime = xmlDoc.SelectSingleNode("//StockQuotes/Quote/Time").InnerText ;
			if(Convert.ToDouble(strChange) >0)
			{
				strChange="up " + strChange;
			}
			else
			{
				strChange="down " + strChange;
			}

string strResult= " symbol " + strSymbol + " Current Trade Price " + strPrice + " Change " + strChange + " at " + strTime;
			return strResult; 
		}

		public XmlDocument GetXmlYahoo(string symbolList )
		{  	   
			string url="http://finance.yahoo.com/q?s=";
			url+=symbolList;
			url+="&d=e";
			WebRequest webRequest = WebRequest.Create(url);
			//this.url = url;
			string beginStr = "";
			try
			{
				WebResponse webResponse = webRequest.GetResponse();
				beginStr = new StreamReader(webResponse.GetResponseStream(), 
					Encoding.Default).ReadToEnd();
				webResponse.Close();
				// clean up some YHOO finance "junk" first so Regex matches won't fail
				beginStr = beginStr.Replace("\n", "");
				beginStr=beginStr.Substring(beginStr.IndexOf("Order Books"));
				beginStr=beginStr.Replace("<font color=ff0020>","");
				beginStr=beginStr.Replace("</font></font>","</font>");
				beginStr=beginStr.Replace("<b>","").Replace("</b>","");
				beginStr=beginStr.Replace("<i>","").Replace("</i>","");
			}
			catch (Exception)
			{
				beginStr = "";
			}					 
			XmlDocument xmlDocument = new XmlDocument();
			XmlElement elemQuotes = xmlDocument.CreateElement("StockQuotes");
			xmlDocument.AppendChild(elemQuotes);
			// match string for our Regex Matches collection			 
			string mainStr = "<td nowrap align=left><font face=arial size=-1><a href=\"(?<href>[^\"]+)\">(?<symbol>[^<]+)</a></font></td><td nowrap align=center><font face=arial size=-1>(?<time>[^<]+)</font></td><td nowrap><font face=arial size=-1>(?<price>[^>]+)</font></td><td nowrap><font face=arial size=-1>(?<change>[^<]+)</font></td>";
			new Regex(mainStr, RegexOptions.Compiled);
			IEnumerator iEnumerator = Regex.Matches(beginStr, mainStr).GetEnumerator();
			try
			{
				//while (iEnumerator.MoveNext())
				iEnumerator.MoveNext();
				{
					Match match = (Match)iEnumerator.Current;
					XmlElement elemQuote = xmlDocument.CreateElement("Quote");
					XmlElement elemSymbol = xmlDocument.CreateElement("Symbol");				                      XmlElement elemTime = xmlDocument.CreateElement("Time");	
					XmlElement elemPrice = xmlDocument.CreateElement("Price");
					XmlElement elemChange = xmlDocument.CreateElement("Change");
					elemSymbol.InnerText = match.Groups["symbol"].Value;
					elemPrice.InnerText = match.Groups["price"].Value.Replace(",", ".");
					elemTime.InnerText=match.Groups["time"].Value.Replace(",", ".");
					elemChange.InnerText = match.Groups["change"].Value.Replace(",", ".");		
					elemQuote.AppendChild(elemSymbol);					
					elemQuote.AppendChild(elemPrice);
					elemQuote.AppendChild(elemChange);
					elemQuote.AppendChild(elemTime);
					xmlDocument.DocumentElement.AppendChild(elemQuote);
				}
			}
			catch(Exception ex)
			{ SpeakText("There was an error. Try Again please.");}			
			return xmlDocument;
		}
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -