Imports Google.Cloud.TextToSpeech.V1
Imports System.IO

Public Class Form1
    '.Ssml                          音声合成マークアップ言語
    '.Text                          テキスト

    'LanguageCode as String         言語タグ BCP-47 例:ja-JP,en-US
    'Name as String                 声の名前
    '                               ja-JP-Standard-A  女性
    '                               ja-JP-Standard-B  女性
    '                               ja-JP-Standard-C  男性
    '                               ja-JP-Standard-D  男性
    '                               ja-JP-Wavenet-A   女性
    '                               ja-JP-Wavenet-B   女性
    '                               ja-JP-Wavenet-C   男性
    '                               ja-JP-Wavenet-D   男性
    'SsmlGender as SsmVoiceGender   声の性別 Female,Male

    'AudioEncoding as AudioEncoding 出力オーディオ形式 Alaw,Linear16,Mp3,Mulaw,OggOpus
    'Pitch as double                音高 -20.0~20.0
    'SampleRateHertz as integer     サンプル周波数(ヘルツ単位)
    'SpeakingRate as double         発話速度 0.25~4.0
    'VolumeGainDb as double         音量 -96~16.0 推奨10.0まで

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "./credential.json", EnvironmentVariableTarget.Process)
        Dim client As TextToSpeechClient = TextToSpeechClient.Create
        Dim body As String = "<speak>音声合成のテストをします。</speak>"
        Dim input As New SynthesisInput With {.Ssml = body}
        Dim voice As New VoiceSelectionParams With {
            .LanguageCode = "ja-JP",
            .Name = "ja-JP-Wavenet-A",
            .SsmlGender = SsmlVoiceGender.Female}
        Dim audioConfig As New AudioConfig With {
            .AudioEncoding = AudioEncoding.Linear16,
            .Pitch = 0,
            .SampleRateHertz = 441000,
            .SpeakingRate = 1.0,
            .VolumeGainDb = 10.0}
        Dim response = client.SynthesizeSpeech(New SynthesizeSpeechRequest With {
                                              .Input = input,
                                              .Voice = voice,
                                              .AudioConfig = audioConfig})
        Using output As Stream = File.Create("./result.wav")
        End Using
    End Sub

End Class