Smoother SAPI
Smoother SAPI
Smoother SAPI
Smoother SAPI
Smoother SAPI
Smoother SAPI Smoother SAPI Smoother SAPI Smoother SAPI Smoother SAPI Smoother SAPI Smoother SAPI Smoother SAPI
Smoother SAPI Smoother SAPI
Smoother SAPI
Go Back  Xtreme Visual Basic Talk > > > Smoother SAPI


Reply
 
Thread Tools Display Modes
  #1  
Old 02-22-2017, 10:08 AM
CodeCruncher CodeCruncher is offline
Junior Contributor
 
Join Date: Jul 2006
Posts: 355
Default Smoother SAPI


It's been a verrrry long time since I have written any code and I am feeling quite rusty so please bear with my stupid questions and basic coding ability.

Below is the result of several days research and trying to remember.

When I use a text box to provide the input the SAPI voice seems a lot smoother than when I put each of the words into a string array.

But I want to be able to smoothly alter the volume, pitch and rate Trackbar Controls and the only way I know how to do that is to add a DoEvents that triggers in between every word.

I tried to work out some Asynchronous garble but every Microsoft example I could find was either incomplete or just plain didn't work (for me anyway).

Could you please look over my code and tell me if there is a smoother way to do this. Running Win 7 64bit and VS2012.

Code:
Option Explicit On

Public Class Config

    Dim intVolume As Int16 = 7, intSpeed As Int16 = 5, intPitch As Int16 = 5
    Dim SAPI = CreateObject("SAPI.spvoice")
    Dim txtArray() As String

    Private Sub Config_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        For Each Voice In SAPI.getvoices
            Dim i As Integer
            cboVoices.Items.Add("" & (i) & " - " & Voice.GetDescription)
            i += 1
        Next

        tbVolume.Value = intVolume
        tbSpeed.Value = intSpeed
        tbPitch.Value = intPitch
        cboVoices.SelectedIndex = 0

        Dim intCount As Int16 = 0, intEndPos As Int16 = 0
        Dim strProcess As String = txtDialog.Text

        Do While strProcess.Length <> 0
            ReDim Preserve txtArray(intCount)
            If InStr(strProcess, " ") > 0 Then
                intEndPos = InStr(strProcess, " ")
                txtArray(intCount) = strProcess.Substring(0, intEndPos - 1)
                strProcess = strProcess.Remove(0, intEndPos)
            Else
                intEndPos = strProcess.Length
                txtArray(intCount) = strProcess.Substring(0, intEndPos)
                strProcess = strProcess.Remove(0, intEndPos)
            End If
            intCount += 1
        Loop

    End Sub

    Private Sub cboVoices_SelectedIndexChanged() Handles cboVoices.SelectedIndexChanged
        txtDialog.BackColor = Color.White
    End Sub

    Private Sub tbVolume_Scroll(sender As Object, e As EventArgs) Handles tbVolume.Scroll
        intVolume = sender.value
    End Sub

    Private Sub tbSpeed_Scroll(sender As Object, e As EventArgs) Handles tbSpeed.Scroll
        intSpeed = sender.Value
    End Sub

    Private Sub tbPitch_Scroll(sender As Object, e As EventArgs) Handles tbPitch.Scroll
        intPitch = sender.value
    End Sub

    Private Sub btnTest_Click(sender As Object, e As EventArgs) Handles btnTest.Click

        With SAPI
            .voice = .getvoices.item(cboVoices.SelectedIndex)
        End With

        Try
            For i = 0 To txtArray.Count - 1
                My.Application.DoEvents()
                SAPI.Speak("<volume level='" & (intVolume * 10) & "'>" & "<rate speed='" & (intSpeed * 2 + -10) & "'>" & _
                    "<pitch middle='" & (intPitch * 5 + -25) & "'>" & txtArray(i))
            Next
            txtDialog.BackColor = Color.LightGreen
        Catch ex As Exception
            txtDialog.BackColor = Color.Red
        End Try

    End Sub

End Class

Last edited by CodeCruncher; 02-22-2017 at 10:47 AM.
Reply With Quote
Reply

Tags
intendpos, dim, private, handles, int16, eventargs, object, sapi, txtdialog.backcolor, string, strprocess, intspeed, txtarrayintcount, intpitch, intvolume, smoother, sender.value, code, intcount, class, strprocess.length, voice, instrstrprocess, strprocess.substring0, strprocess.remove0


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Smoother SAPI
Smoother SAPI
Smoother SAPI Smoother SAPI
Smoother SAPI
Smoother SAPI
Smoother SAPI Smoother SAPI Smoother SAPI Smoother SAPI Smoother SAPI Smoother SAPI Smoother SAPI
Smoother SAPI
Smoother SAPI
 
Smoother SAPI
Smoother SAPI
 
-->