The IBM Text to Speech service provides APIs that use IBM’s speech-synthesis capabilities to turn text into a very natural-sounding speech in many different languages, dialects, and voices.
Text to Speech provides at least one male or female voice (and sometimes both) for each language, and the audio is streamed back to you with minimal delay.
Watson SDKs abstract much of the complexity associated with application development. By providing programming interfaces in languages that you already know, they can help you get up and running quickly with IBM Watson services.
Go SDK is one of the IBM-supported Watson SDKs, and this post will outline how to use Go SDK to access the IBM Text to Speech service. Users who are interested in using Golang to access Text to Speech may benefit from this content.
Note: As a prerequisite, please install the latest version of Golang. The following example is using version go1.14.
Step 1: Create a sample script
- Create a new folder named
demo
. - Use any text editor to create a file called
testSpeech.go
under the new folder. Use the following for the content of the script:
Step 2: Create a test script
- Use any text editor to create a file called
speech_test.go
under the new folder. Use the following for the content of the script:
Step 3: Update the Go SDK library
- Under the
demo
folder, run the following command: - Update the go.mod file
- A file called
go.mod
will be created with the following content: - Update the content to the following:
- Note: If you don’t update the go.mod file, you may encounter this error later:
- A file called
- Run the following test:
- Then, run this script:
The
outputspeech.wav
should be created successfully.
Summary
It’s easy to get started with IBM Watson SDK for Golang, and the GitHub repository is actively developed. If you encounter any issue with the SDK, you may first try the StackOverflow, but if you don’t have any luck there, please feel free to raise a GitHub issue at the repository and the SDK developers will investigate it.