Text to Speech(TTS) in Golang. Part 2

2 min readFeb 14, 2021


This is the continuation of previous article which you can read at https://iamkochukulam.medium.com/text-to-speech-tts-in-golang-3e913e83fcea

Last week we spoke about general introduction about Text to Speech. Today we continue to understand a speech to text program written by Tibor Hegedűs .

Tibor Hegedűs has contributed to the Golang community a package which provides a functionality on Text to Speech. The package communicates with Google Server and downloads the audio files to the local path.

Credits: https://github.com/egonelbre/gophers

On a Program level, its uses Speech package provided by Go. The Speech Package provides access to the Cloud Speech API.

Mr. Hegedűs has tried to achieve this functionality in the below 3 steps.

1) Speak downloads speech and plays it using player

2) Create the folder if does not exists.

3) Download the voice file if does not exists.

You can download his repo from

go get “github.com/hegedustibor/htgo-tts”

Speech takes the inputs which are path and Language.
speech := htgotts.Speech{Folder: “audio”, Language: “en”}

Language parameter can be changed from English(en) to others as per preference. About path, it checks if the folder is available else it tries to create the folder. It uses createFolderIfNotExists for creating a folder.

It use’s the GET method once the url is provided. Google api along with url.QueryEscape and language is provided.

url := fmt.Sprintf(“http://translate.google.com/translate_tts?ie=UTF-8&total=1&idx=0&textlen=32&client=tw-ob&q=%s&tl=%s", url.QueryEscape(text), speech.Language)


Finally it implements the MD5 hash algorithm as defined in RFC 1321. Package md5 implements the MD5 hash algorithm. Sum returns the MD5 checksum of the data. It will create a hash for example: b0804ec967f48520697662a204f5fe72PS
hash := md5.Sum([]byte(name))

Extra info: Go website suggests us that MD5 is cryptographically broken and should not be used for secure applications.

So what are the packages, Functions, HTTP request Methods used in this program which could be the key takeaway:

crypto/md5: Implements the MD5 hash algorithm
encoding/hex : Package hex implements hexadecimal encoding and decoding
net/http: Package http provides HTTP client and server implementations.

Speech: Package speech provides access to the Cloud Speech API.
Extra info: Go prefers we use Use package cloud.google.com/go/speech/apiv1 instead.

http uses the GET response method retrieves data from the provided URL.

This article attempts to understand Text2Speech in Golang by a Go contributor Tibor Hegedűs by getting into its packages, functions and HTTP verbs which orchestrates to create a TTS(Text2Speech) symphony :)

Thanks and Happy Learning!




A Gopher in the world of Go