Dart Flutter Command Line Google Text To Speech API Tutorial

Jeff McMorris
3 min readFeb 14, 2020

In this tutorial, I created a simple command line app in dart. It converts text to speech using the google text to speech api and saves the file as an mp3. I reviewed another command line tutorial here which was quite helpful. I also used some code from this great flutter package

Full code for this app can be found here.

So first steps, you need to install dart and stagehand. Stagehand is a dart project generator for command line apps. Stagehand is installed with this command.

pub global activate stagehand

Next create the project.

mkdir text_to_speech
cd text_to_speech
stagehand console-full

This will make a scaffolding for the dart project.

Now replace the main.dart file located in the /bin folder with this.

main.dart

This main.dart uses the dart package args which parses the command line for extra arguments. We need it to get the text and the filename the user supplies. We then pass that data into the textToSpeech function. Below is how we call the function on the command line.

dart bin/main.dart -t 'Say something interesting' -f speech

-t is the text to convert to speech -f is the filename for the mp3.

--

--