- App To Convert Speech To Text In Mac Pro
- Free Text To Speech App
- Best Text To Speech App
- App To Convert Speech To Text In Mac Pdf
- Apple Speech To Text App
- Text To Speech Mac Download
- App To Convert Speech To Text In Mac Download
In this tutorial, you'll build a Flask web app that uses Azure Cognitive Services to translate text, analyze sentiment, and synthesize translated text into speech. Our focus is on the Python code and Flask routes that enable our application, however, we will help you out with the HTML and Javascript that pulls the app together. If you run into any issues let us know using the feedback button below.
Here's what this tutorial covers:
Jun 12, 2018 Invicta TTS Invicta TTS is a very simple free Text To Speech app available on the Mac App Store. Once you open up the app, it presents you with a text box where you can enter or paste any text which will be then converted to speech. The app is very lightweight and minimal in nature with everything being to the point. Feb 28, 2017 How to convert text to audio on mac for free,mac tips and tricks,text to audio on mac easy step. Free text to speech using the default Mac OS app.
- Get Azure subscription keys
- Set up your development environment and install dependencies
- Create a Flask app
- Use the Translator to translate text
- Use Text Analytics to analyze positive/negative sentiment of input text and translations
- Use Speech Services to convert translated text into synthesized speech
- Run your Flask app locally
Tip
If you'd like to skip ahead and see all the code at once, the entire sample, along with build instructions are available on GitHub.
What is Flask?
Flask is a microframework for creating web applications. This means Flask provides you with tools, libraries, and technologies that allow you to build a web application. This web application can be some web pages, a blog, a wiki or go as substantive as a web-based calendar application or a commercial website.
For those of you who want to deep dive after this tutorial here are a few helpful links:
Prerequisites
Let's review the software and subscription keys that you'll need for this tutorial.
- An IDE or text editor, such as Visual Studio Code or Atom
- Chrome or Firefox
- A Translator subscription key (Note that you aren't required to select a region.)
- A Text Analytics subscription key in the West US region.
- A Speech Services subscription key in the West US region.
Create an account and subscribe to resources
As previously mentioned, you're going to need three subscription keys for this tutorial. This means that you need to create a resource within your Azure account for:
- Translator
- Text Analytics
- Speech Services
Use Create a Cognitive Services Account in the Azure portal for step-by-step instructions to create resources.
Important
For this tutorial, please create your resources in the West US region. If using a different region, you'll need to adjust the base URL in each of your Python files.
Set up your dev environment
Before you build your Flask web app, you'll need to create a working directory for your project and install a few Python packages.
Create a working directory
Open command line (Windows) or terminal (macOS/Linux). Then, create a working directory and sub directories for your project:
Change to your project's working directory:
Create and activate your virtual environment with virtualenv
Let's create a virtual environment for our Flask app using virtualenv
. Using a virtual environment ensures that you have a clean environment to work from.
In your working directory, run this command to create a virtual environment:macOS/Linux:
We've explicitly declared that the virtual environment should use Python 3. This ensures that users with multiple Python installations are using the correct version.
Windows CMD / Windows Bash:
To keep things simple, we're naming your virtual environment venv.
The commands to activate your virtual environment will vary depending on your platform/shell:
Platform Shell Command macOS/Linux bash/zsh source venv/bin/activate
Windows bash source venv/Scripts/activate
Command Line venvScriptsactivate.bat
PowerShell venvScriptsActivate.ps1
After running this command, your command line or terminal session should be prefaced with
venv
.You can deactivate the session at any time by typing this into the command line or terminal:
deactivate
.
Note
Python has extensive documentation for creating and managing virtual environments, see virtualenv.
Install requests
Requests is a popular module that is used to send HTTP 1.1 requests. There's no need to manually add query strings to your URLs, or to form-encode your POST data.
To install requests, run:
Note
If you'd like to learn more about requests, see Requests: HTTP for Humans.
Install and configure Flask
Next we need to install Flask. Flask handles the routing for our web app, and allows us to make server-to-server calls that hide our subscription keys from the end user.
To install Flask, run:
Let's make sure Flask was installed. Run:
The version should be printed to terminal. Anything else means something went wrong.
To run the Flask app, you can either use the flask command or Python's -m switch with Flask. Before you can do that you need to tell your terminal which app to work with by exporting the
FLASK_APP
environment variable:macOS/Linux:
Windows:
Create your Flask app
In this section, you're going to create a barebones Flask app that returns an HTML file when users hit the root of your app. Don't spend too much time trying to pick apart the code, we'll come back to update this file later.
What is a Flask route?
Let's take a minute to talk about 'routes'. Routing is used to bind a URL to a specific function. Flask uses route decorators to register functions to specific URLs. For example, when a user navigates to the root (/
) of our web app, index.html
is rendered.
Let's take a look at one more example to hammer this home.
This code ensures that when a user navigates to http://your-web-app.com/about
that the about.html
file is rendered.
While these samples illustrate how to render html pages for a user, routes can also be used to call APIs when a button is pressed, or take any number of actions without having to navigate away from the homepage. You'll see this in action when you create routes for translation, sentiment, and speech synthesis.
Get started
Open the project in your IDE, then create a file named
app.py
in the root of your working directory. Next, copy this code intoapp.py
and save:This code block tells the app to display
index.html
whenever a user navigates to the root of your web app (/
).Next, let's create the front-end for our web app. Create a file named
index.html
in thetemplates
directory. Then copy this code intotemplates/index.html
.Let's test the Flask app. From the terminal, run:
Open a browser and navigate to the URL provided. You should see your single page app. Press Ctrl + C to kill the app.
Translate text
Now that you have an idea of how a simple Flask app works, let's:
- Write some Python to call the Translator and return a response
- Create a Flask route to call your Python code
- Update the HTML with an area for text input and translation, a language selector, and translate button
- Write Javascript that allows users to interact with your Flask app from the HTML
Call the Translator
The first thing you need to do is write a function to call the Translator. This function will take two arguments: text_input
and language_output
. This function is called whenever a user presses the translate button in your app. The text area in the HTML is sent as the text_input
, and the language selection value in the HTML is sent as language_output
.
- Let's start by creating a file called
translate.py
in the root of your working directory. - Next, add this code to
translate.py
. This function takes two arguments:text_input
andlanguage_output
. - Add your Translator subscription key and save.
Add a route to app.py
Next, you'll need to create a route in your Flask app that calls translate.py
. This route will be called each time a user presses the translate button in your app.
For this app, your route is going to accept POST
requests. This is because the function expects the text to translate and an output language for the translation.
Flask provides helper functions to help you parse and manage each request. In the code provided, get_json()
returns the data from the POST
request as JSON. Then using data['text']
and data['to']
, the text and output language values are passed to get_translation()
function available from translate.py
. The last step is to return the response as JSON, since you'll need to display this data in your web app.
In the following sections, you'll repeat this process as you create routes for sentiment analysis and speech synthesis.
Open
app.py
and locate the import statement at the top ofapp.py
and add the following line:Now our Flask app can use the method available via
translate.py
.Copy this code to the end of
app.py
and save:
Update index.html
Now that you have a function to translate text, and a route in your Flask app to call it, the next step is to start building the HTML for your app. The HTML below does a few things:
- Provides a text area where users can input text to translate.
- Includes a language selector.
- Includes HTML elements to render the detected language and confidence scores returned during translation.
- Provides a read-only text area where the translation output is displayed.
- Includes placeholders for sentiment analysis and speech synthesis code that you'll add to this file later in the tutorial.
Let's update index.html
.
Open
index.html
and locate these code comments:Replace the code comments with this HTML block:
The next step is to write some Javascript. This is the bridge between your HTML and Flask route.
Create main.js
The main.js
file is the bridge between your HTML and Flask route. Your app will use a combination of jQuery, Ajax, and XMLHttpRequest to render content, and make POST
requests to your Flask routes.
In the code below, content from the HTML is used to construct a request to your Flask route. Specifically, the contents of the text area and the language selector are assigned to variables, and then passed along in the request to translate-text
.
The code then iterates through the response, and updates the HTML with the translation, detected language, and confidence score.
- From your IDE, create a file named
main.js
in thestatic/scripts
directory. - Copy this code into
static/scripts/main.js
:
Test translation
Let's test translation in the app.
Navigate to the provided server address. Type text into the input area, select a language, and press translate. You should get a translation. If it doesn't work, make sure that you've added your subscription key.
Tip
If the changes you've made aren't showing up, or the app doesn't work the way you expect it to, try clearing your cache or opening a private/incognito window.
Press CTRL + c to kill the app, then head to the next section.
Analyze sentiment
The Text Analytics API can be used to perform sentiment analysis, extract key phrases from text, or detect the source language. In this app, we're going to use sentiment analysis to determine if the provided text is positive, neutral, or negative. The API returns a numeric score between 0 and 1. Scores close to 1 indicate positive sentiment, and scores close to 0 indicate negative sentiment.
In this section, you're going to do a few things:
- Write some Python to call the Text Analytics API to perform sentiment analysis and return a response
- Create a Flask route to call your Python code
- Update the HTML with an area for sentiment scores, and a button to perform analysis
- Write Javascript that allows users to interact with your Flask app from the HTML
Call the Text Analytics API
Let's write a function to call the Text Analytics API. This function will take four arguments: input_text
, input_language
, output_text
, and output_language
. This function is called whenever a user presses the run sentiment analysis button in your app. Data provided by the user from the text area and language selector, as well as the detected language and translation output are provided with each request. The response object includes sentiment scores for the source and translation. In the following sections, you're going to write some Javascript to parse the response and use it in your app. For now, let's focus on call the Text Analytics API.
- Let's create a file called
sentiment.py
in the root of your working directory. - Next, add this code to
sentiment.py
. - Add your Text Analytics subscription key and save.
Add a route to app.py
Let's create a route in your Flask app that calls sentiment.py
. This route will be called each time a user presses the run sentiment analysis button in your app. Like the route for translation, this route is going to accept POST
requests since the function expects arguments.
Open
app.py
and locate the import statement at the top ofapp.py
and update it:Now our Flask app can use the method available via
sentiment.py
.Copy this code to the end of
app.py
and save:
Update index.html
Now that you have a function to run sentiment analysis, and a route in your Flask app to call it, the next step is to start writing the HTML for your app. The HTML below does a few things:
- Adds a button to your app to run sentiment analysis
- Adds an element that explains sentiment scoring
- Adds an element to display the sentiment scores
Open
index.html
and locate these code comments:Replace the code comments with this HTML block:
Update main.js
In the code below, content from the HTML is used to construct a request to your Flask route. Specifically, the contents of the text area and the language selector are assigned to variables, and then passed along in the request to the sentiment-analysis
route.
The code then iterates through the response, and updates the HTML with the sentiment scores.
From your IDE, create a file named
main.js
in thestatic
directory.Copy this code into
static/scripts/main.js
:
Test sentiment analysis
App To Convert Speech To Text In Mac Pro
Let's test sentiment analysis in the app.
Navigate to the provided server address. Type text into the input area, select a language, and press translate. You should get a translation. Next, press the run sentiment analysis button. You should see two scores. If it doesn't work, make sure that you've added your subscription key.
Tip
If the changes you've made aren't showing up, or the app doesn't work the way you expect it to, try clearing your cache or opening a private/incognito window.
Press CTRL + c to kill the app, then head to the next section.
Convert text-to-speech
The Text-to-speech API enables your app to convert text into natural human-like synthesized speech. The service supports standard, neural, and custom voices. Our sample app uses a handful of the available voices, for a full list, see supported languages.
In this section, you're going to do a few things:
- Write some Python to convert text-to-speech with the Text-to-speech API
- Create a Flask route to call your Python code
- Update the HTML with a button to convert text-to-speech, and an element for audio playback
- Write Javascript that allows users to interact with your Flask app
Call the Text-to-Speech API
Let's write a function to convert text-to-speech. This function will take two arguments: input_text
and voice_font
. This function is called whenever a user presses the convert text-to-speech button in your app. input_text
is the translation output returned by the call to translate text, voice_font
is the value from the voice font selector in the HTML.
Let's create a file called
synthesize.py
in the root of your working directory.Next, add this code to
synthesize.py
.Add your Speech Services subscription key and save.
Add a route to app.py
Let's create a route in your Flask app that calls synthesize.py
. This route will be called each time a user presses the convert text-to-speech button in your app. Like the routes for translation and sentiment analysis, this route is going to accept POST
requests since the function expects two arguments: the text to synthesize, and the voice font for playback.
Open
app.py
and locate the import statement at the top ofapp.py
and update it:Now our Flask app can use the method available via
synthesize.py
.Copy this code to the end of
app.py
and save:
Update index.html
Now that you have a function to convert text-to-speech, and a route in your Flask app to call it, the next step is to start writing the HTML for your app. The HTML below does a few things:
- Provides a voice selection drop-down
- Adds a button to convert text-to-speech
- Adds an audio element, which is used to play back the synthesized speech
Open
index.html
and locate these code comments:Replace the code comments with this HTML block:
Next, locate these code comments:
Replace the code comments with this HTML block:
- Make sure to save your work.
Update main.js
In the code below, content from the HTML is used to construct a request to your Flask route. Specifically, the translation and the voice font are assigned to variables, and then passed along in the request to the text-to-speech
route.
The code then iterates through the response, and updates the HTML with the sentiment scores.
- From your IDE, create a file named
main.js
in thestatic
directory. - Copy this code into
static/scripts/main.js
: - You're almost done. The last thing you're going to do is add some code to
main.js
to automatically select a voice font based on the language selected for translation. Add this code block tomain.js
:
Test your app
Let's test speech synthesis in the app.
Navigate to the provided server address. Type text into the input area, select a language, and press translate. You should get a translation. Next, select a voice, then press the convert text-to-speech button. the translation should be played back as synthesized speech. If it doesn't work, make sure that you've added your subscription key.
Tip
If the changes you've made aren't showing up, or the app doesn't work the way you expect it to, try clearing your cache or opening a private/incognito window.
That's it, you have a working app that performs translations, analyzes sentiment, and synthesized speech. Press CTRL + c to kill the app. Be sure to check out the other Azure Cognitive Services.
Get the source code
The source code for this project is available on GitHub.
Next steps
Whether you prefer articles read to you while you do something else or trying to grasp a new foreign language or even for specially abled students, TTS (short for text-to-speech) has proved to be very useful.
In our previous articles we saw some of the best text to speech apps for Windows and Android. And today, we take a look at some of the best TTS options available for Macs.
Text To Speech For Mac
1. macOS TTS
Before we get too ahead of ourselves and start downloading third party apps, it is very trivial to know that macOS itself comes with a built-in TTS and you can use it anywhere on your computer from the Notes app to any browser.
To get started, highlight or select the text which you want to be read and then right click, go to Speech and then to Start Speaking; and your Mac should start reading the text to you. It also supports a lot of other languages other than English and there are a lot of voices to choose from in all the languages. To change the language option simply go to Accessibility > Speech. Although some voices are very robotic, there are a few which aren’t and sound more like a human.
But the TTS is far from perfect; it is very basic and barebones and lacks options like pause/play, picking up from a selected word instantly and a lot more.
Quick Tip: It blew my mind and might even blow yours to know that the native TTS on Mac also supports converting your text into audio files. Just select the required text, right click and go to Services > Add to iTunes as a spoken track. The text will be converted to an audio track and added to your iTunes library.
Pros:
– Built-in system wide
– Lots of voice options
– Converting text to iTunes track
Cons:
– No Pause/Play
– Have to select manually all the words to be read
– No instant pickup
Verdict:
Overall, the TTS that comes with macOS is very barebones without all the bells and whistles and should be perfect for somebody looking for a basic TTS experience without even buying or installing any third party software.
2. Invicta TTS
Invicta TTS is a very simple free Text To Speech app available on the Mac App Store.
Once you open up the app, it presents you with a text box where you can enter or paste any text which will be then converted to speech. The app is very lightweight and minimal in nature with everything being to the point.
Although the app is very basic, unlike the built in TTS of Mac OS, it does add the option of playing or pausing the audio which becomes crucial when listening to long texts or articles. The voice settings cannot be changed but the in built voice does the job pretty good enough.
Pros:
– Minimal and Light
– Play/Pause Option
Cons:
– Cannot read documents automatically
– Supports only English
Verdict:
If you need a simple and light TTS app and might be listening to long articles, Invicta TTS does the job pretty well but do remember that it can only read English.
Free Text To Speech App
Link: Get Invicta TTS on the App Store
Price: Free
3. Natural Reader
The next app on our list is Natural Reader which is an extremely powerful TTS software available not only on Mac OS but also on Windows, iOS, Android and even has an online reader.
The app comes in many flavours, each with its fair share of features for the price. The free version comes with basic TTS features along with the ability to read directly from file formats such as Docx, PDF, ePub and Txt. It also has a floating bar which can be used to read text while you are in other applications. The next option or the Personal version, at a steep $100, allows you to read web pages directly, converting text to audio files and syncing everything between your phone apps. There are also Professional and Ultimate versions which add OCR support and a bunch of natural voices.
Best Text To Speech App
Pros:
– Support for file formats
– Convert to audio files
– Cross Platform
– OCR Support
Cons:
– Pricey
– No instant pickup
Verdict:
All the features of Natural Reader definitely come at a price and you should be able to decide whether it is a suit for you with respect to your investment in TTS, but even for a casual user the free version works really well. Overall, Natural reader is not just best text to speech software with natural voices, but since it also support PDF, it’s also a good option for those who are looking for PDF Voice Reader for macOS.
App To Convert Speech To Text In Mac Pdf
Pricing Options: Pricing for Natural Reader
Link: Download Natural Reader from here
The software combined with the tiny, six-button mouse is one of the most elegant achievements by the Apple design team. It's not extensible, however. Perhaps Apple wants complete control. Perhaps the company is staffed by design fascists.
4. Read Aloud
Read Aloud is not exactly a stand alone Mac app but instead a Chrome extension which might appeal to some people. Considering how many posts and articles are read on the internet everyday, we had to include Read Aloud.
It is completely free and once you install it, its icon will appear in the extension bar which you can now use to read any webpage or any online article, just by a single click. When it is in work, you get a play/pause button along with a forward or rewind button which can be used to advance or backtrack paragraphs. Considering it is free, the voice options are really good and feel very natural and premium.
Pros:
– Great natural voice
– Forward or rewind by paragraphs
– Listen to webpages
Cons:
– Works only on Chrome
Verdict:
Suggesting Read Aloud is very straight forward; if you are someone who reads a lot on the internet and are looking for a free TTS software for that, nothing beats Read Aloud.
Price: Free
Link: Download Read Aloud from the Chrome Store
5. Capti Voice
Capti Voice is probably the most polished and well rounded TTS software available for the Mac and the award are only there to justify that. Starting off, Capti Voice uses your browser for the app to function instead of a stand alone Mac application. Don’t worry, you can still use it while you are offline as it stores all its data locally and personally I have had no issues.
Capti Voice has a subscription based model and even the free version has a lot to offer from various file format supports to text search while the premium versions add features like creating playlists, OCR Support and intelligent dictionary lookup. The voices offered across all the platforms are very high quality and commendable.
Quick Tip: Don’t forget to use the Chrome extension which allows you to save articles or webpages to be read later by Capti Voice.
Apple Speech To Text App
Pros:
– Cross platform with mobile apps
– Create Playlists
– Dictionary lookup
– Shortcuts to get around
Cons:
– No standalone app
– Syncs only when you add to cloud storage
Verdict:
Overall, Capti Voice is a really compelling app with features packed to the brim and is very similar to natural Reader but with a subscription based model. It is really the best TTS experience you can get on Mac OS.
Pricing Info: Pricing Options for Capti Voice
Link: Download Capti Voice from here
Text To Speech Mac Download
6. Honorable Mentions
CereProc has some of the most natural sounding computer speeches available on the market, which you can use to replace the default voice on your Mac (also available for other platforms). There are a lot of high quality voice packs to choose from and each costs around $35.
Zamzar is a free online service which you can use to convert your text to audio files or mp3s. Unlike the iTunes spoken track which you can use only on Apple devices, you can use it on any platform without any hassle.
Wrapping up: Best Text to Speech for Mac
So these were some of the TTS software available on the Mac and we hope we made your decision a little bit easier. If you are someone who reads mainly on the internet, Read Aloud is by far the best free option. Although a little limited, the built-in TTS feature seems to work just fine, but it can be a pain for long stretches of texts or long articles for which there is Invicta which is also free.
Natural Reader and Capti Voice both are spectacular TTS apps with a lot of plans to choose from, but I guess what it comes down to is the paying model. Natural reader is a one time purchase and should be better if you feel you will be invested in TTS for a long time whereas Capti Voice follows a subscription based model also with a one week free trial. Thanks for reading and do comment below which one is your favorite TTS app on Mac OS.
App To Convert Speech To Text In Mac Download
Read: Make your Devices Read Out Text, With Text to Speech