1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
Imports System.IO Imports Google.Cloud.TextToSpeech.V1 'Install-Package Google.Cloud.TextToSpeech.V1 -Version 2.1.0' Module Program Const JsonPath As String = "C:\Users\MyUser\repos\GoogleSpeechToText\GoogleSpeechToText\client_secrets.json" Dim MyTextToSpeechClient As TextToSpeechClient Dim OutputFile As String = "Output.mp3" Sub Main(args As String()) Dim FileText As String = IO.File.ReadAllText("D:\TextFileToConvert.txt").Trim Run(FileText).Wait() Process.Start(OutputFile) End Sub Public Async Function Run(ByVal Text As String) As Task 'Upload to Youtube Try Dim MyTextToSpeechClientBuilder As New TextToSpeechClientBuilder() MyTextToSpeechClientBuilder.CredentialsPath = JsonPath MyTextToSpeechClient = MyTextToSpeechClientBuilder.Build() Dim response = MyTextToSpeechClient.ListVoices("en") For Each Myvoice In response.Voices Console.WriteLine($"{Myvoice.Name} ({Myvoice.SsmlGender}); Language codes: {String.Join(", ", Myvoice.LanguageCodes)}") Next Catch ex As Exception Debug.WriteLine(ex.Message) End Try Dim input As SynthesisInput = New SynthesisInput With { .Text = Text } Dim voice As VoiceSelectionParams = New VoiceSelectionParams With { .LanguageCode = "en-US", .SsmlGender = SsmlVoiceGender.Neutral } Dim config As AudioConfig = New AudioConfig With { .AudioEncoding = AudioEncoding.Mp3 } Dim response2 = MyTextToSpeechClient.SynthesizeSpeech(New SynthesizeSpeechRequest With { .Input = input, .Voice = voice, .AudioConfig = config }) Using output As Stream = File.Create(OutputFile) response2.AudioContent.WriteTo(output) Console.WriteLine($"Audio content written to file: " & OutputFile) End Using End End Function End Module |