Make Python Talk
Build Apps with Voice Control and Speech Recognition
by Mark Liu
MAKE PYTHON TALK. Copyright 2021 by Mark Liu.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying, recording, or by any information storage or retrieval system, without the prior written permission of the copyright owner and the publisher.
ISBN-13: 978-1-7185-0156-0 (print)
ISBN-13: 978-1-7185-0157-7 (ebook)
Publisher: William Pollock
Production Manager: Rachel Monaghan
Production Editor: Paula Williamson
Developmental Editor: Liz Chadwick
Cover Illustrator: Gina Redman
Interior Design: Octopod Studios
Technical Reviewer: Noah Spahn
Copyeditor: Sharon Wilkey
Compositor: Jeff Lytle, Happenstance Type-O-Rama
Proofreader: Paula Fleming
Indexer: JoAnne Burek
For information on book distributors or translations, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1.415.863.9900; info@nostarch.com
www.nostarch.com
Library of Congress Control Number: 2021938060
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other product and company names mentioned herein may be the trademarks of their respective owners. Rather than use a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
Dedicated to Ivey, Andrew, and all MS Finance students (past, present, and future) at the University of Kentucky.
About the Author
Dr. Mark H. Liu is the founding director of the Master of Science in Finance program at the University of Kentucky, where he holds the title of Associate Professor of Finance with tenure. He has a Ph.D. in finance from Boston College, and has been published in top finance journals, including Journal of Financial Economics, Journal of Financial and Quantitative Analysis, and Journal of Corporate Finance. Dr. Liu has more than 20 years of coding experience in C++, SAS, Stata, and Python and runs Python workshops for Finance master students at the University of Kentucky. He has also incorporated Python in finance courses he is teaching.
About the Technical Reviewer
Noah Spahn is presently enjoying the role of Software Engineer for the Computer Security Group at UCSB (known as SecLab) and their world-famous hacking team: Shellphish. Prior to his current academic role, he ran his own consulting business, allowing him to work on a wide variety of projects, with a broad spectrum and languages, and collaborate with varying teams. Fluency in Python has opened many doors for Spahn, providing the opportunity to contribute to the areas of natural sciences (oceanography, ecohydrology, seismology), computer science (network traffic analysis, machine learning, binary analysis), open-source projects (NASA, Kubernetes, and others), as well as many practical applications. Spahn holds a Master of Software Engineering degree from California State University, Fullerton. He has taught courses in Python at the University of California and Santa Barbaras interdisciplinary Collaboratory, and has taught an upper-division course on the concepts of programming languages at Westmont College. Spahn is glad to teach anyone who is interested in learning.
ACKNOWLEDGMENTS
Many people have helped to make this book a reality. A portion of this book was developed while I was preparing Python workshops for MS Finance students at the University of Kentucky in the past few years. Several Finance master and Ph.D. students helped tremendously in the process: Joe Farizo, James Keyser, Blake Best, and especially my teaching assistants at the time Mike Farrell and Patrick Mullins. Id like to thank all MS Finance students for keeping me motivated to learn new Python skills in order to show them how useful and interesting coding is.
Id also like to thank Bill Pollock and Barbara Yien at No Starch Press for guiding me through the editorial process. Special thanks to my developmental editor Liz Chadwick, whose pursuit for perfection has greatly improved the book. She helped me find the delicate balance between over-explaining and not enough detail.
Many thanks to the technical reviewer of the book Noah Spahn. He doesnt simply check if the code works correctly, he also makes sure the scripts are as efficient as they can be. A case in point is that he pushed me to find a way to make the self-made modules in different chapters consistent. This prompted me to use the self-made Python package in the book. He went way beyond just checking the scripts, and frequently edited the writing to help explain technical details in the book.
Last but not least, Id like to thank my wife Ivey Zhang and my son Andrew Liu for being so supportive in this journey. In the past couple of years, I probably have spent more time with the book than with them over the weekends and holidays. I am indebted to them the most.
Introduction
Banks are essentially technology firms.
Hugo Banziger, former chief risk officer at Deutsche Bank
Python is currently the worlds most popular coding language, having overtaken more long established languages like Java and C. Once you start to code in Python, its easy to see why. The two main advantages of Python are its simplicity and openness. Python code is relatively close to plain English, so with only a little experience, you can often guess what a script is trying to accomplish.
Python is open source, meaning not only that the software is free to use for everyone but also that other users can create and alter libraries. In fact, Python has a vast ecosystem from which you can get resources and help from members in the community. Python programmers can share their code with one another, so instead of building everything from scratch, you can import modules designed by others, as well as share your modules with others in the Python community.
When people heard that I was writing a Python book on speech recognition and text to speech, their reaction was generally the same: I thought you were a finance professor. My typical answer is the Hugo Banziger quote that opens this chapter, made shortly after the 2008 financial crisis. Nowadays, you can replace banks with corporations in any other industrycar manufacturers, retailers, anything reallyand the quote still rings true. Technology is in every aspect of our lives these days. The future is here and now.
Python has been the worlds most popular coding language since 2018. Long before that, Python was the leading programming language in the finance world, with applications in financial services, portfolio management, algorithmic trading, cryptocurrency, and so on.
NOTE
The article Python Is Becoming the Worlds Most Popular Coding Language in The Economist (https://www.economist.com/graphic-detail/2018/07/26/python-is-becoming-the-worlds-most-popular-coding-language/) has details on the increasing popularity of Python.