Click here to Skip to main content
15,892,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
After updating the sdk to v11 and installing new TTS voices, I found one has to edit the Reg. Now all the voices show in the control <panel> Text-to-Speech and all the voices test.

I found an Article using SAPI in C# and all voices work; however; converting the C# to VB.net I get an error "Voice not Reg" Note:<window anna=""> works

Any on have a fix?

VB.Net
Add Reference
Microsoft Speech Object Library: V 11


Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Imports SpeechLib
Imports System.Threading

Exploring the SpVoice class of MS SAPI 5.1 to use the various available features for TTS

' By Sabah u Din Irfan, Writen in C# above link
' Converted to VB.NET


Public Class Form1
Dim Speech As SpVoice
Dim Sp As Integer = -3 ' Speed +10 to -10
Dim Vl As Integer = 100 ' Volume 0 to 100


Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Speech = CreateObject("SAPI.spvoice")
GetVoiceSaip()
TrackBar1.Value = Sp
lbSpeed.Text = TrackBar1.Value
TrackBar2.Value = Vl
lbVol.Text = TrackBar2.Value
End Sub
Private Sub GetVoiceSaip()
Try
cmbVoices.Items.Clear()
For Each Token As ISpeechObjectToken In Speech.GetVoices("", "")
cmbVoices.Items.Add(Token.GetDescription(49))
Next
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try
cmbVoices.SelectedIndex = 0

End Sub

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Speech.Volume = Vl
Speech.Rate = Sp
Try
Speech.Speak(TextBox1.Text, SpeechVoiceSpeakFlags.SVSFlagsAsync)
Catch ex As Exception

End Try

End Sub

Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
lbSpeed.Text = TrackBar1.Value
Sp = TrackBar1.Value
End Sub

Private Sub TrackBar2_Scroll(sender As Object, e As EventArgs) Handles TrackBar2.Scroll
lbVol.Text = TrackBar2.Value
Vl = TrackBar2.Value
End Sub

Private Sub cmbVoices_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cmbVoices.SelectedIndexChanged
Speech.Voice = Speech.GetVoices("", "").Item(cmbVoices.SelectedIndex)
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.Clear()
End Sub
End Class
Posted

1 solution

There won't be any essential difference if you correctly translate C# code to VB.NET. If, by some weird reason, you have to do such a translation, you don't have to make it manually. Automatic translation (especially the off-line way based on ILSpy) will do the trick perfectly. Please see my past answer: Code Interpretation, C# to VB.NET[^].

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900