Voice Activated Trading Bot Powered By IBM Watson Text-to-Speech Service
This blog post is a proof of concept for a talking tradebot which announces stock prices when they cross certain thresholds. It demonstrates the powerful Text to Speech service from IBM Watson and utilizes PubNub Real-time Data Streaming Network.
Voice enabled devices are leaping forward, and speech is becoming the dominant bot interface. Digital assistants, or bots, as they are widely known nowadays, speak more like humans. Their popularity is growing with a multitude of apps that can make your life easier, and their application is found in domains like customer service, home automation, chat and news readers to name a few.
This article showcases the power of speech agents with a stock market trading example, where continuous price updates can be heard instead of watched on screen. Furthermore, a use case is presented for one such stock trading scenario using a voice activated trading bot.
This post was originally published in IBM Blog
Introduction to IBM Text to Speech Service
The IBM Watson Text to Speech service is part of the offerings on the IBM Bluemix platform. It provides an API to convert written text to natural-sounding speech.
The service supports various languages and voices and accents to choose. It even supports customizable cadence, tone, emotions and expressiveness such as speaking about good news, or an apology, or uncertainty. You can experience a demo of this service at the Text to Speech demo site.
In this post, you will learn to develop a helper bot application called TradeBot. The TradeBot will speak out a message when selected stock prices cross certain predefined threshold levels.
TradeBot, A Voice Automated Stock Trading Agent
Everyone wants to make extra money and trading in the stock market can be a great way for additional income. One important trait of successful traders is that they always keep themselves updated with stock price movements.
As a trader, you would usually log on to a website or open an app and keep watching the prices continuously. This monotonous approach demands more time and attention on your part. On the other extreme, there are some algorithmic trading software products available, like Ninja Trader or Tradestation (but they have their own set of features which we may not prefer).
To build a speech-enabled trading bot, called TradeBot, you’ll use IBM Text to Speech service. TradeBot is like a voice automated stock trading plugin. It acts as a friendly stock trading assistant by giving out audible alerts when your favorite stock crosses predefined upper or lower limit.
You’ll be able to configure the Tradebot with some stock counters and define their upper and lower thresholds. The TradeBot will give natural sounding feedback in male voice if the lower threshold is crossed and in female voice if upper threshold is crossed.
Components of the TradeBot Agent
The TradeBot system makes use of two major components: IBM Text to Speech and PubNub Functions.
The speech synthesis capabilities of IBM Text to Speech service are what gives the Tradebot its voice capabilities. The HTTP REST APIs access this service, via PubNub Functions, a serverless microservice and part of the PubNub Global Data Stream Network. PubNub Functions host the service side business logic for the Tradebot and orchestrates the client requests with the IBM Text To Speech service.
PubNub works on the publish/subscribe model of communication, where a publisher can publish a message on a channel, and any subscriber subscribed to that channel can receive it.
The sequence of operations to activate voice alerts for the Tradebot is as follows.
- The stock exchange captures random movement of stock prices and publishes them.
- Once a stock price crosses a predefined threshold, the app publishes a text message to PubNub network on a particular channel.
- Within PubNub network, the PubNub Functions microservice calls IBM Text to Speech service API which returns a URL of the synthesized speech from the text message.
- PubNub Functions adds this URL to the text message payload and publishes the payload to TradeBot client which is already subscribed to the particular channel.
- TradeBot subscriber client downloads the synthesized speech message and then plays it back.
Since we do not have access to real stock market feed, the stock exchange environment is simulated with random price variations.
Building The Voice Assisted Trading Bot App
Before you attempt to recreate this demo, make sure that you are subscribed to IBM Bluemix and PubNub account. Visit IBM Bluemix and PubNub to register yourself. Both the services offer a free tier subscription plan to play around with their services.
Here are the software components and cloud services used to build Tradebot:
- IBM Text to Speech service – A service deployed on the IBM Bluemix platform. IBM Text to Speech API provides the service for converting text messages to speech.
- PubNub – A real time data streaming network based on a publish-subscribe mechanism. Devices publish messages on a particular channel to PubNub network acting as a broker, and these messages are received by devices subscribed to that channel. PubNub also offers one useful functionality called Functions which is a lightweight runtime that can execute any business logic within the PubNub network. An PubNub Function can process published messages either before or after they are passed on to subscriber devices.
TradeBot In Action
After building the app and creating all required services, you can start experiencing a live speech-enabled bot trading environment. Take a look and listen to how the TradeBot behaves in response to stock price variations.
As you can see and hear in the video, two separate scripts are run. The first script runs the TradeBot for generating voice alerts, and the second script simulates the stock exchange.
Enhancements To Voice-Activated Stock Trading App
Congratulations! You have successfully implemented a voice-enabled trading bot using IBM Text to Speech service and PubNub.
What more can you do to enhance this bot?
As you experienced from the demo, this TradeBot actuates your hearing senses. For intraday traders, this is a real lifesaver as the visual sense cannot always keep pace with the fluctuating stock prices. Hence, one of the notable feature additions to this app can be to speak periodic price updates without waiting to cross the thresholds.
Also, PubNub Functions can be extended to hook this app to a real stock feed from various exchanges across the world. PubNub also makes it easier to scale the TradeBot app to deliver speech messages across a number of devices simultaneously. Besides that, using the Storage & Playback of PubNub, the TradeBot can give audible feedback about historic price movements of a stock.
IBM Text to Speech service with its low latency synthesis of audio makes it easy to augment voice-enabled features to your application. The capability to customize the speech further with expressiveness and voice transformation makes it simpler to move away from the monotony of robotic voices.
One of the most impactful use cases of this service can be applications for vision-impaired people. There are a number of other potential applications as well. For example, reading aloud the morning news when you get ready for the day, or reading aloud texts or mails while driving so you can keep your eyes on the road are great use cases. Another important area is in development of chatbots for customer service interactions.
So what are you waiting for? Gear up and start building awesome voice-enabled applications. And please do share your feedback on TradeBot!