4 Replies - 8189 Views - Last Post: 21 July 2009 - 01:40 PM Rate Topic: -----

#1 zerogee  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 0
  • View blog
  • Posts: 91
  • Joined: 20-August 08

Text to Speech

Post icon  Posted 17 July 2009 - 01:04 PM

I want to use text to speech to say what is in my textbox. I have added the reference into the solution (MS speech object libarary) and inserted the "imports speechlib but i am getting an error when building.

error BC30451: Name 'voice' is not declared.

according to turtorials i have everything right, but i am still gettiing this error. here is my code;

Imports SpeechLib

Public Class Form1


	Private Sub ReservButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReservButton.Click

		Dim ad As New Ad
		Dim AdPrice As Double

		If Not IsNumeric(TeleTextBox) And TeleTextBox.Text <> vbNullString Then

			MsgBox("Sorry, only numbers allowed")

			TeleTextBox.Text = vbNullString

		End If

		If Not IsDate(RundateTextBox) = False Then

			MsgBox("Sorry, date format is mm/dd/yy")
			RundateTextBox.Text = vbNullString


		End If

		' Radiobutton restrictions set

		If InsdfrRadioButton.Checked = True Then
			OutbkRadioButton.Enabled = False
		End If

		If BusRadioButton.Checked = True Then
			IntpgRadioButton.Enabled = False
			InsdfrRadioButton.Enabled = False
			InsbkRadioButton.Enabled = False
			OutbkRadioButton.Enabled = False
		End If

		' Make sure all Textbox's have been filled out

		If CompTextBox.Text = String.Empty Or TeleTextBox.Text = String.Empty Or RundateTextBox.Text = String.Empty Then
			MessageBox.Show(" You must enter all information", "Buzz Advertising", MessageBoxButtons.OK, MessageBoxIcon.Error)
		End If

		'Determine base price based on checked ad size radiobutton

		If FullRadioButton.Checked = True Then
			ad.Size = 225.0
		End If

		If HalfRadioButton.Checked = True Then
			ad.Size = 225.0 * 0.65
		End If

		If QtrRadioButton.Checked = True Then
			ad.Size = 225.0 * 0.4
		End If

		If BusRadioButton.Checked = True Then
			ad.Size = 35.0
		End If

		' Determine markup based upon checked location radiobutton

		If OutbkRadioButton.Checked = True Then
			ad.Location = 1.4
		End If

		If InsbkRadioButton.Checked = True Then
			ad.Location = 1.15
		End If

		If InsdfrRadioButton.Checked = True Then
			ad.Location = 1.2
		End If

		If IntpgRadioButton.Checked = True Then
			ad.Location = 1.0
		End If


		AdPrice = ad.CalculateAd()
		If ad.Size = 35.0 Then
			AdPrice = 35.0
		End If

		'Display total price and Text to Voice'
		AdpriceTextBox.Text = AdPrice.ToString("C2")
		voice.Speak("Your final ad price is" & AdpriceTextBox.Text)



the very last "voice.speak" is the problem child. anyone has any suggestions???

Is This A Good Question/Topic? 0
  • +

Replies To: Text to Speech

#2 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1639
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Text to Speech

Posted 17 July 2009 - 01:56 PM

I dont see anywhere in your code where voice is declared (just like the error is telling you). A variable needs to be declared and set to it's proper type before it can be used

'Replace "SomeType" as whatever type voice is
Dim voice As SomeType



Also, since you're using VB.NET (and not VB6) you should not be using legacy libraries (such as MsgBox) and start using the native libraries of the .Net framework, like the MessageBox Class :)
Was This Post Helpful? 1
  • +
  • -

#3 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2257
  • View blog
  • Posts: 9,445
  • Joined: 29-May 08

Re: Text to Speech

Posted 17 July 2009 - 01:59 PM

Try the .net version System.Speech.

Then I prefer using an extension method so it available on any string.
Dim TheSpeaker As New Speech.Synthesis.SpeechSynthesizer()

 <Runtime.CompilerServices.Extension()> _
 Sub Say(ByRef t As String)
  TheSpeaker.SelectVoiceByHints(Synthesis.VoiceGender.Female, Synthesis.VoiceAge.Adult)
  TheSpeaker.Speak(t)
 End Sub


Like so.
 Sub Main()
 Dim TestText As String="Hello zerogee"
 Dim Anum As String = "124"
  TestText .Say()
  Anum.Say()
  Console.ReadKey()
 End Sub


This post has been edited by AdamSpeight2008: 17 July 2009 - 02:00 PM

Was This Post Helpful? 0
  • +
  • -

#4 Yaroslav94  Icon User is offline

  • D.I.C Regular

Reputation: 5
  • View blog
  • Posts: 294
  • Joined: 15-July 09

Re: Text to Speech

Posted 21 July 2009 - 01:04 PM

Try using SAPI?
Was This Post Helpful? 0
  • +
  • -

#5 StanKnight  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 25
  • Joined: 14-April 09

Re: Text to Speech

Posted 21 July 2009 - 01:40 PM

Hey there! Yeah just reading your code and I don't see voice being declared... So I'm second hand for that being your case :). - Stan :^:

View Postzerogee, on 17 Jul, 2009 - 12:04 PM, said:

I want to use text to speech to say what is in my textbox. I have added the reference into the solution (MS speech object libarary) and inserted the "imports speechlib but i am getting an error when building.

error BC30451: Name 'voice' is not declared.

according to turtorials i have everything right, but i am still gettiing this error. here is my code;

Imports SpeechLib

Public Class Form1


	Private Sub ReservButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReservButton.Click

		Dim ad As New Ad
		Dim AdPrice As Double

		If Not IsNumeric(TeleTextBox) And TeleTextBox.Text <> vbNullString Then

			MsgBox("Sorry, only numbers allowed")

			TeleTextBox.Text = vbNullString

		End If

		If Not IsDate(RundateTextBox) = False Then

			MsgBox("Sorry, date format is mm/dd/yy")
			RundateTextBox.Text = vbNullString


		End If

		' Radiobutton restrictions set

		If InsdfrRadioButton.Checked = True Then
			OutbkRadioButton.Enabled = False
		End If

		If BusRadioButton.Checked = True Then
			IntpgRadioButton.Enabled = False
			InsdfrRadioButton.Enabled = False
			InsbkRadioButton.Enabled = False
			OutbkRadioButton.Enabled = False
		End If

		' Make sure all Textbox's have been filled out

		If CompTextBox.Text = String.Empty Or TeleTextBox.Text = String.Empty Or RundateTextBox.Text = String.Empty Then
			MessageBox.Show(" You must enter all information", "Buzz Advertising", MessageBoxButtons.OK, MessageBoxIcon.Error)
		End If

		'Determine base price based on checked ad size radiobutton

		If FullRadioButton.Checked = True Then
			ad.Size = 225.0
		End If

		If HalfRadioButton.Checked = True Then
			ad.Size = 225.0 * 0.65
		End If

		If QtrRadioButton.Checked = True Then
			ad.Size = 225.0 * 0.4
		End If

		If BusRadioButton.Checked = True Then
			ad.Size = 35.0
		End If

		' Determine markup based upon checked location radiobutton

		If OutbkRadioButton.Checked = True Then
			ad.Location = 1.4
		End If

		If InsbkRadioButton.Checked = True Then
			ad.Location = 1.15
		End If

		If InsdfrRadioButton.Checked = True Then
			ad.Location = 1.2
		End If

		If IntpgRadioButton.Checked = True Then
			ad.Location = 1.0
		End If


		AdPrice = ad.CalculateAd()
		If ad.Size = 35.0 Then
			AdPrice = 35.0
		End If

		'Display total price and Text to Voice'
		AdpriceTextBox.Text = AdPrice.ToString("C2")
		voice.Speak("Your final ad price is" & AdpriceTextBox.Text)



the very last "voice.speak" is the problem child. anyone has any suggestions???

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1