如何获得随机演讲

时间:2017-07-03 16:22:04

标签: vb.net

我试图用语音制作简单的节目,并且无法弄清楚如何让它说出随机的东西。这就是我所做的,但它不起作用。我发现谷歌的例子,但只有数字,我不知道该怎么做。所以,如何使程序随机说话#Hello; Hi,Hi或Hey" ?

  If e.KeyCode = Keys.Enter Then
        Dim SAPI
        Dim r As Random = New Random
        SAPI = CreateObject("SAPI.spvoice")
        SAPI.Speak(r.Next("Hello", "Hi", "Hey"))
    End If

1 个答案:

答案 0 :(得分:0)

创建一个字符串数组并随机化所调用的值。

Dim speech() As String = {"Hello", "Hi", "Howdy"}

If e.KeyCode = Keys.Enter Then
    Dim SAPI
    Dim r As Random = New Random
    SAPI = CreateObject("SAPI.spvoice")
    SAPI.Speak(speech(r.Next(0, speech.Length)))
End If