Share via


SpVoice Rate property (SAPI 5.3)

Microsoft Speech API 5.3

Object: SpVoice

Rate Property

The Rate property gets and sets the speaking rate of the voice.

Values for the Rate property range from -10 to 10, which represent the slowest and the fastest speaking rates, respectively.

At the beginning of each Speak or SpeakStream method, the voice sets its speaking rate according to the value of its Rate property, and speaks the entire stream at that rate. The Rate property can be changed at any time, but the actual speaking rate will not reflect the changed property value until it begins a new stream.

Syntax

Set: SpVoice.Rate = Long
Get: Long = SpVoice.Rate

Parts

  • SpVoice
    The owning object.
  • Long
    Set: A Long variable that sets the property value.
    Get: A Long variable that gets the property value.

Example

The following Visual Basic form code demonstrates the use of the Rate and the Volume properties. To run this code, create a form with the following controls:

  • A command button called Command1
  • A text box called Text1
  • A vertical scroll bar called VScroll1
  • A horizontal scroll bar called HScroll1

Paste this code into the Declarations section of the form.

The Form_Load procedure creates a voice object and associates the VScrollbar with the voice's Volume property and the HScrollbar with the voice's Rate property. Adjusting the scroll bars changes the settings of the Volume and Rate properties. The Command1_Click procedure speaks a phrase in order to demonstrate the effects of the changes.

  
Option Explicit

Private V As SpeechLib.SpVoice

Private Sub Form_Load()
    On Error GoTo EH

    Set V = New SpeechLib.SpVoice

    VScroll1.Min = 0
    VScroll1.Max = 100
    VScroll1.Value = V.Volume

    HScroll1.Min = -10
    HScroll1.Max = 10
    HScroll1.Value = V.Rate

    Text1.Text = "Vol: " & VScroll1.Value & ";  Rate: " & HScroll1.Value

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub Command1_Click()
    On Error GoTo EH

    V.Speak "The quick brown fox jumped over the lazy dog.", SVSFlagsAsync

EH:
    If Err.Number Then ShowErrMsg
End Sub

Private Sub HScroll1_Change()

    V.Rate = HScroll1.Value
    Text1.Text = "Vol: " & VScroll1.Value & ";  Rate: " & HScroll1.Value

End Sub

Private Sub VScroll1_Change()

    V.Volume = VScroll1.Value
    Text1.Text = "Vol: " & VScroll1.Value & ";  Rate: " & HScroll1.Value

End Sub

Private Sub ShowErrMsg()

    ' Declare identifiers:
    Dim T As String

    T = "Desc: " & Err.Description & vbNewLine
    T = T & "Err #: " & Err.Number
    MsgBox T, vbExclamation, "Run-Time Error"
    End

End Sub