0% found this document useful (0 votes)
21 views

Download ebooks file Make Python Talk Mark H Liu all chapters

Make

Uploaded by

olsbylivia29
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

Download ebooks file Make Python Talk Mark H Liu all chapters

Make

Uploaded by

olsbylivia29
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

Get ebook downloads in full at ebookmeta.

com

Make Python Talk Mark H Liu

https://ebookmeta.com/product/make-python-talk-mark-h-liu/

OR CLICK BUTTON

DOWNLOAD NOW

Explore and download more ebook at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Make Python Talk 1st Edition Mark Liu

https://ebookmeta.com/product/make-python-talk-1st-edition-mark-liu/

ebookmeta.com

Make Python Talk Build Apps with Voice Control and Speech
Recognition 1st Edition Mark Liu

https://ebookmeta.com/product/make-python-talk-build-apps-with-voice-
control-and-speech-recognition-1st-edition-mark-liu/

ebookmeta.com

Let's Talk Python: Young coders build software (MEAP V06)


Pavel Anni

https://ebookmeta.com/product/lets-talk-python-young-coders-build-
software-meap-v06-pavel-anni/

ebookmeta.com

Killer Fame 1st Edition Mary Stone Stacy O Hare

https://ebookmeta.com/product/killer-fame-1st-edition-mary-stone-
stacy-o-hare/

ebookmeta.com
Atlas of Lip and Nose Plastic and Cosmetic Surgery Jianhua
Liu (Editor)

https://ebookmeta.com/product/atlas-of-lip-and-nose-plastic-and-
cosmetic-surgery-jianhua-liu-editor/

ebookmeta.com

Grumpy Girl and Amaryllis Sunshine Guy Grumpy Girl Romance


Dirty Hoe Love Book 5 1st Edition Brynn Hale

https://ebookmeta.com/product/grumpy-girl-and-amaryllis-sunshine-guy-
grumpy-girl-romance-dirty-hoe-love-book-5-1st-edition-brynn-hale/

ebookmeta.com

Natural Language Processing with Transformers: Building


Language Applications with Hugging Face 1st Edition
Tunstall
https://ebookmeta.com/product/natural-language-processing-with-
transformers-building-language-applications-with-hugging-face-1st-
edition-tunstall/
ebookmeta.com

Spectrums of Amyotrophic Lateral Sclerosis Heterogeneity


Pathogenesis and Therapeutic Directions 1st Edition

https://ebookmeta.com/product/spectrums-of-amyotrophic-lateral-
sclerosis-heterogeneity-pathogenesis-and-therapeutic-directions-1st-
edition/
ebookmeta.com

Russian Imperialism Revisited From Disengagement to


Hegemony 1st Edition Domitilla Sagramoso

https://ebookmeta.com/product/russian-imperialism-revisited-from-
disengagement-to-hegemony-1st-edition-domitilla-sagramoso/

ebookmeta.com
Narcocapitalism Life in the Age of Anaesthesia Theory
Redux 1st Edition Laurent De Sutter

https://ebookmeta.com/product/narcocapitalism-life-in-the-age-of-
anaesthesia-theory-redux-1st-edition-laurent-de-sutter/

ebookmeta.com
R L Y
A
E ESS
A C C
N O S TA R C H P R E S S
E A R LY A C C E S S P R O G R A M :
FEEDBACK W ELCOME!

Welcome to the Early Access edition of the as yet unpublished Make Python
Talk by Mark Liu! As a prepublication title, this book may be incomplete and
some chapters may not have been proofread.
Our goal is always to make the best books possible, and we look forward
to hearing your thoughts. If you have any comments or questions, email us
at earlyaccess@nostarch.com. If you have specific feedback for us, please
include the page number, book title, and edition date in your note, and
we’ll be sure to review it. We appreciate your help and support!
We’ll email you as new chapters become available. In the meantime,
enjoy!
M A K E P Y T H O N TA L K
MARK LIU
Early Access edition, 3/30/21

Copyright © 2021 by Mark Liu.

ISBN 13: 978-1-7185-0156-0 (print)


ISBN 13: 978-1-7185-0157-7 (ebook)

Publisher: William Pollock


Executive Editor: Barbara Yien
Production Editor: Paula Williamson
Developmental Editor: Liz Chadwick
Cover and Interior Design: Octopod Studios
Cover Illustrator: Gina Redman
Technical Reviewer: Noah Spahn
Copyeditor: Sharon Wilkey
Compositor: Jeff Lytle, Happenstance Type-O-Rama
Proofreader: Paula Fleming

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 trade-
marked 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.

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 informa-
tion storage or retrieval system, without the prior written permission of the copyright owner
and the publisher.

The information in this book is distributed on an “As Is” basis, without warranty. While every
precaution has been taken in the preparation of this work, neither the author nor No Starch
Press, Inc. shall have any liability to any person or entity with respect to any loss or damage
caused or alleged to be caused directly or indirectly by the information contained in it.
CONTENTS

Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Part I: Getting Started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 1: Install Python via Anaconda and Spyder . . . . . . . . .
Chapter 2: Python Refresher . . . . . . . . . . . . . . . . . . . . . . . . . .
Part II: Learning to Talk . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 3: Speech Recognition . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 4: Make Python Talk . . . . . . . . . . . . . . . . . . . . . . . . 1
Chapter 5: Speaking Applications . . . . . . . . . . . . . . . . . . . . 17
Chapter 6: Web Scraping Podcasts, Radios, and Videos . . . . 39
Chapter 7: Building a Virtual Personal Assistant . . . . . . . . . . 61
Chapter 8: Know-it-all VPA . . . . . . . . . . . . . . . . . . . . . . . . . 83
Part III: Interactive Games . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 9: Graphics and Animation with the turtle Module . . . 95
Chapter 10: Tic-Tac-Toe . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Chapter 11: Connect Four . . . . . . . . . . . . . . . . . . . . . . . . 133
Chapter 12: guess-the-word Game . . . . . . . . . . . . . . . . . . 153
Chapter 13: Smart Games: Adding Intelligence . . . . . . . . . 167
Part IV: Going Further . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Chapter 14: Financial Applications . . . . . . . . . . . . . . . . . . 195
Chapter 15: Stock Market Watch . . . . . . . . . . . . . . . . . . . 219
Chapter 16: Use Other Languages: Translator
Chapter 17: Ultimate VPA
Appendix A: Useful Speech Modules
Appendix B: Answers to End of Chapter Exercises
Index

The chapters in red are included in this Early Access PDF.


Make Python Talk (Early Access) © 2021 by Mark Liu

4
M A K E P Y T H O N TA L K

In this chapter, you’ll learn how to make


Python talk back to you in a human voice.
You’ll first install the text-to-speech mod-
ule based on your operating system, and then
teach Python to speak aloud whatever you enter on
your computer. You’ll also add the speech-recognition
feature you learned in Chapter 3 and get Python to
repeat your own speech. Finally, you’ll build a real-
world application to use voice inputs to ask Python
to calculate the area of a rectangle and tell you the
answer in a human voice.
To save space, you’ll put all text-to-speech-related code in a self-made
module. Once you know how to do that, you can import the module into
any script that needs the text-to-speech feature.
Make Python Talk (Early Access) © 2021 by Mark Liu

You’ll also learn how to ask Python to read a long text file such as a
news article aloud. Before you begin, set up the folder /mpt/ch04/ for this
chapter.

NE W SKILL S

• Installing speech-related modules depending on your operating system


• Adjusting properties of your text-to-speech module
• Learning how to create a module that is portable cross-platform
• Combining the text-to-speech module with speech recognition so a com-
puter can repeat what you said
• Making the computer solve a problem and answer you in a human voice

Install the Text-to-Speech Module


Python has two commonly used text-to-speech modules: pyttsx3 and gTTS.
If you use Windows, you’ll install pyttsx3 and use it throughout the book.
In the Windows operating system, the pyttsx3 module works offline, has a
human-like voice, and lets you adjust the speech properties—namely, the
speed, volume, and gender of the voice output.
However, the pyttsx3 module works differently in Mac and Linux. The
voice sounds robotic, and the speech properties are not easily adjustable.
Therefore, you’ll install gTTS if you use Mac or Linux. The gTTS module
requires an internet connection since it uses the Google Translate text-to-
speech application programming interface (API). Further, gTTS does not
play the sound directly. It saves the voice as an audio file or file-like object.
You’ll have to use your own audio player to hear the voice. The voice gen-
erated by gTTS is very human-like.
In Chapter 2, you built a virtual environment called chatting for speech
recognition. You’ll install the pyttsx3 or gTTS module in the same virtual
environment so your script will have both the speech-recognition and text-
to-speech features.

Set Up
If you are using Windows, go to the “Install pyttsx3 in Windows” section
and skip the “Install gTTS in Mac or Linux” section. Otherwise, skip the
“Install pyttsx3 in Windows” section and go to the “Install gTTS in Mac or
Linux” section.

Install pyttsx3 in Windows


The pyttsx3 module is not in the Python standard library, so you’ll need to
install it via pip.

2 Chapter 4
Make Python Talk (Early Access) © 2021 by Mark Liu

If you haven’t already set up your chatting virtual environment, go back


to Chapter 2 now and follow the instructions to do so. Then activate the
virtual environment chatting in the Anaconda prompt by executing the
following:

conda activate chatting

With your chatting virtual environment activated, enter this:

pip install pyttsx3

Follow the instructions onscreen to finish the installation.

Install gTTS in Mac or Linux


The gTTS module is not in the Python standard library, so you’ll need to
install it via pip.
If you haven’t already set up your chatting virtual environment, go back
to Chapter 2 now and follow the instructions to do so. Then activate the vir-
tual environment chatting in a terminal by executing the following:

conda activate chatting

With your chatting virtual environment activated in your terminal, enter


this:

pip install gtts

Follow the instructions onscreen to finish the installation.

Test Your Text-to-Speech Module


Before beginning, you’ll check that your text-to-speech module is properly
installed and working. Based on your operating system, skip the sections
that don’t apply to you.

Run a Sample Script in Windows


With your virtual environment activated and Spyder open, copy the script
test_pyttsx3.py into your editor and save it in your chapter folder. If you pre-
fer, you can download the file from the book’s resources through https://
www.nostarch.com/makepythontalk/.

import pyttsx3
1 engine = pyttsx3.init()
2 engine.say("hello, how are you?")
engine.runAndWait()

First import the pyttsx3 module to the script. Then use init() to initiate
a text-to-speech engine in the pyttsx3 module and call it engine 1. The say()
function in the pyttsx3 module converts the text to a speech signal, and

Make Python Talk 3


Make Python Talk (Early Access) © 2021 by Mark Liu

prepares to send it to the speaker 2. The runAndWait() function then sends


the actual speech signal to the speaker so you can hear the sound. The
runAndWait() function also keeps the engine running so that when you want
to convert text to speech later in the script, you don’t need to initiate the
engine again.
Run test_pyttsx3.py line by line by using the F9 key to help you under-
stand how each line of code functions.

NOTE The say() function in the pyttsx3 module only converts the text to a speech signal
and prepares to send it to the speaker. It does not do the actual speaking. To hear the
sound, use runAndWait(), which sends the speech signal to the speaker.

If the module is correctly installed, when you finish running the whole
script, you should hear a voice saying, “Hello, how are you?” If not, recheck
the instructions and make sure that the speaker on your computer is work-
ing properly at the right volume. I’ll discuss later in this chapter how to cus-
tomize the speed, volume, and the voice gender associated with the pyttsx3
module.

Run a Sample Script in Mac or Linux


We’ll use the gtts-cli tool (cli stands for command line) to convert text to
speech, instead of converting text to an audio file, and then play it. The
gtts-cli tool is faster than the alternative method. Once you install the gTTS
module, the gtts-cli tool is available in the command line in your virtual
environment. The gtts-cli tool converts the text to a file-like object, and you
have to choose which audio player to play it. I find that the mpg123 player
works well.
First, you need to install the mpg123 player on your computer. If you
are using Mac, run the following command on a terminal:

brew install mpg123

If you are using Linux, run the following two commands on a terminal:

sudo apt-get update


sudo apt-get install mpg123

Once you’re finished, with your virtual environment activated, run the
following command in a terminal:

gtts-cli --nocheck "hello, how are you?" | mpg123 -q -

If you have correctly installed everything, you should hear a voice saying,
“Hello, how are you?” If not, recheck the instructions and make sure that the
speaker on your computer is working properly at the right volume. Further,
since you have installed the gTTS module in your virtual environment, you
have to run the preceding command with your virtual environment acti-
vated. Otherwise, it won’t work.

4 Chapter 4
Make Python Talk (Early Access) © 2021 by Mark Liu

The nocheck option in this command is to speed up execution. The q


flag instructs the module not to display copyright and version messages,
even in an interactive mode. Make sure you don’t miss the hyphen at the
end of the command.
Next, you’ll use the os module in Python to execute commands in a
subshell.
Copy the test_gtts.py script into your Spyder editor and save it in your
chapter folder. The script is also available at the book’s resources through
https://www.nostarch.com/makepythontalk.

import os

os.system('gtts-cli --nocheck "hello, how are you?" | mpg123 -q -')

First import the os module to the script. Then use system()to execute a
command in a subshell to achieve the same effect of running the command
in a terminal. As a result, the gtts-cli tool is used to convert text to a file-like
object. After that, the mpg123 player plays the sound object so you can hear
a human voice.

NOTE You don’t need to explicitly import the gTTS module in test_gtts.py because you use
the gtts-cli tool in the command line, even though the gTTS module is used.

If you’ve done everything correctly, you should hear a voice saying,


“Hello, how are you?”

Convert Text to Voice in Windows


Now let’s practice converting written text input into a human voice in
Windows. With your virtual environment activated and Spyder open, copy
the script tts_windows.py, as shown in Listing 4-1, into your editor and save
and run it.

import pyttsx3

engine = pyttsx3.init()
1 while True:
2 inp = input("What do you want to covert to speech?\n")
3 if inp == "done":
print(f"You just typed in {inp}, goodbye!")
engine.say(f"You just typed in {inp}, goodbye!")
engine.runAndWait()
break
4 else:
print(f"You just typed in {inp}")
engine.say(f"You just typed in {inp}")
engine.runAndWait()
5 continue

Listing 4-1: Converting text to voice in Windows

Make Python Talk 5


Make Python Talk (Early Access) © 2021 by Mark Liu

After importing the pyttsx3 module and initiating a text-to-speech engine,


start an infinite loop to take user text input 1. In each iteration, the script
asks for text input at the IPython console 2. If you want to stop the script,
enter done 3, and the script will print and say in a human voice, “You just
typed in done; goodbye!” After that, the loop stops, and the script quits
running.
If the text input is not done, the else branch runs 4, and the script speaks
your text input out loud in a human voice. After that, the script goes to the
next iteration and takes your text input again 5.
The following is sample output from the script (user input is in bold):

What do you want to covert to speech?


Python is great!
You just typed in Python is great!

What do you want to covert to speech?


Hello, world!
You just typed in Hello, world!

What do you want to covert to speech?


done
You just typed in done; goodbye!

Convert Text to Voice in Mac or Linux


Now we’ll practice converting written text input into a human voice in Mac
or Linux. With your virtual environment activated and Spyder open, copy
the script tts_mac_linux.py (Listing 4-2) into your editor, and save and run it.

import os

while True: 1
inp = input("What do you want to covert to speech?\n") 2
if inp == "done": 3
print(f"You just typed in {inp}, goodbye!")
os.system(f'gtts-cli --nocheck "You just typed in {inp}, goodbye!" | mpg123 -q -')
break
else: 4
print(f"You just typed in {inp}")
os.system(f'gtts-cli --nocheck "You just typed in {inp}" | mpg123 -q -')
continue 5

Listing 4-2: Converting text to voice in Mac and Linux

After importing the os module so you can run commands in a subshell,


start an infinite loop to take user text input 1. In each iteration, the script
asks for text input at the IPython console 2. If you want to stop the script,
enter done 3, and the script will print and say in a human voice, “You just
typed in done; goodbye!” After that, the loop stops, and the script quits
running.

6 Chapter 4
Make Python Talk (Early Access) © 2021 by Mark Liu

If the text input is not done, the else branch runs 4, and the script speaks
your text input out loud in a human voice. After that, the script goes to the
next iteration and takes your text input again 5.
The following is sample output from the script (user input is in bold):

What do you want to covert to speech?


Python is great!
You just typed in Python is great!

What do you want to covert to speech?


Hello, world!
You just typed in Hello, world!

What do you want to covert to speech?


done
You just typed in done; goodbye!

Repeat After Me
We’ll start with a simple script that hears what you say aloud and repeats it
in a human voice. This script serves two purposes. First, you’ll learn how the
script takes your voice inputs, and which words are easiest for the script to
understand—some uncommon words won’t be understood. Second, you’ll
learn how to put both the speech-recognition and text-to-speech features
in the same script, so you can communicate with the computer through
human voices only.
We’ll also make the script portable cross-platform. The script will auto-
matically choose the pyttsx3 module if you are using Windows and the gTTS
module otherwise.
Start a new script, name it repeat_me.py, and enter the code in Listing 4-3.
Make sure to save it in your chapter folder. You’ll also need to copy your
mysr.py file from Chapter 3 and paste it into the same folder, as we’ll need
voice_to_text() from that script.

# Make sure you put mysr.py in the same folder as this script
from mysr import voice_to_text

import platform 1
if platform.system() == "Windows":
import pyttsx3
engine = pyttsx3.init()
else:
import os

while True:
print('Python is listening...')
inp = voice_to_text() 2
if inp == "stop listening": 3
print(f'You just said {inp}; goodbye!')
if platform.system() == "Windows":

Make Python Talk 7


Make Python Talk (Early Access) © 2021 by Mark Liu

engine.say(f'You just said {inp}, goodbye!')


engine.runAndWait()
else:
os.system(f'gtts-cli --nocheck "You just said {inp}; goodbye!" | mpg123 -q -')
break

else:
print(f'You just said {inp}')
if platform.system() == "Windows": 4
engine.say(f'You just said {inp}')
engine.runAndWait()
else:
os.system(f'gtts-cli --nocheck "You just said {inp}" | mpg123 -q -')
continue

Listing 4-3: Repeating aloud

WARNING Remember to put mysr.py in the same folder as Listing 4-3. Otherwise, the speech-
recognition feature won’t work! Yes, I’ve said this before, but it bears repeating until it
sinks in.

We first import the voice_to_text() function from the mysr module to


convert voice commands into a string variable. We then import the platform
module, which lets the script automatically identify your operating system
and choose the appropriate command for you 1. If you are using Windows,
the script imports the pyttsx3 module and initiates a text-to-speech engine.
Otherwise, the script imports the os module so you can use the gtts-cli tool
in a subshell.
We then start an infinite loop to take voice inputs. The script takes your
voice command and converts it into a string variable called inp 2. If you say,
“Stop listening” 3 to the microphone, the script will say aloud, “You just
said stop listening; goodbye!” After that, the script stops. The script uses
either the pyttsx3 module or the gtts-cli tool to achieve that based on your
operating system.
If you say anything else into the microphone, the loop will keep run-
ning. At each iteration, the script will repeat what you said out loud 4.
The following is the output from the script after I said, “Hello, how are
you” and “Stop listening” into the microphone sequentially:

Python is listening...
You just said hello
Python is listening...
You just said how are you
Python is listening...
You just said stop listening; goodbye!

NOTE If you pause often while the script stands by, the script may say, “You just said” in a
human voice again and again when you are not speaking. To avoid that, you can
modify repeat_me.py by removing the You just said part ( 4 in Listing 4-3).

8 Chapter 4
Make Python Talk (Early Access) © 2021 by Mark Liu

Customize the Speech


In this section, you’ll learn how to customize the speech produced by your
text-to-speech module. You can adjust the speed and volume of the speech
as well as the identity of the voice in the pyttsx3 module in Windows. If you
are using Mac or Linux, the only thing you can customize is the speed of
the voice in the gTTS module.
Skip any of the following subsections that don’t apply to your operating
system.

Retrieve Default Settings in the pyttsx3 Module in Windows


First, you need to see the default values of the parameters for the speed,
volume, and identity of the voice in the pyttsx3 module in Windows.
This script will retrieve the default settings for your speech module. In
Spyder, enter the code in Listing 4-4 and save it as pyttsx3_property.py in the
chapter folder.

import pyttsx3

engine = pyttsx3.init()
1 voices = engine.getProperty('voices')
2 for voice in voices:
print(voice)
3 rate = engine.getProperty("rate")
print("the default speed of the speech is", rate)
vol = engine.getProperty("volume")
print("the default volume of the speech is", vol)

Listing 4-4: Retrieving the default settings

At 1, you use getProperty()to obtain the properties of the voices used in


the engine. You then iterate through all the voice objects in the list voices
2 and print out individual voice objects.
You use getProperty() 3 to obtain the properties of the speed and print
the default speed, and then do the same for the default volume.
If you run this script in Windows, you’ll see the default settings for your
speech script, similar to the following output:

<Voice id=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_DAVID_11.0
name=Microsoft David Desktop - English (United States)
languages=[]
gender=None
age=None>
<Voice id=HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0
name=Microsoft Zira Desktop - English (United States)
languages=[]
gender=None
age=None>
the default speed of the speech is 200
the default volume of the speech is 1.0

Make Python Talk 9


Make Python Talk (Early Access) © 2021 by Mark Liu

Here you can see the two voices available to the pyttsx3 module. The
first voice is named David with a male voice tone; the second voice is named
Zira with a female voice tone. The default voice tone is David, hence the
male voice you hear in test_pyttsx3.py.
The default speech speed is 200 words per minute. The default volume
is set at 1. You’ll learn how to adjust the speed, volume, and ID in the pyttsx3
module in Windows next.

Adjust Speech Properties in the pyttsx3 Module in Windows


This script will change the default settings so you can hear a voice with the
speed, volume, and ID that you prefer. Save Listing 4-5 as pyttsx3_adjust.py.

import pyttsx3
engine = pyttsx3.init()
voice_id = 1
1 voices = engine.getProperty('voices')
2 engine.setProperty('voice', voices[voice_id].id)
3 engine.setProperty('rate', 150)
4 engine.setProperty('volume', 1.2)
5 engine.say("This is a test of my speech id, speed, and volume.")
engine.runAndWait()

Listing 4-5: Adjusting some settings

Let’s choose the second voice ID, which has a female voice. At 1, the
script obtains the voice objects available in the text-to-speech engine and
saves them in a list called voices. We choose the second object in the list voices
by giving the index [1] 2, which has a female voice tone. The setProperty()
function takes two arguments: the property to set, and the value to set it to.
We set the value to voices[voiceID].id to choose the id value of the female
voice object in Windows, which is HKEY_LOCAL_MACHINE\SOFTWARE\
Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0. If you want to
change to the male voice in Windows, you can use voices[0].id instead.
Here we set the speech speed to 150 words per minute 3. Most of us
speak at the rate of about 125 words per minute in our daily lives. For faster
speech, set it to a number greater than 125, and for slower speech, set it to a
number below 125.
We set the volume to 1.2 4, which is louder than the default value of
1. You can set this to higher or lower than 1 based on your preference and
speakers.
At 5, the script converts the text in say() into speech by using the
adjusted properties. Try running this script multiple times with different
combinations of parameters until you find the best combination for you.
You can always come back to this script and adjust.

Customize the gTTS Module in Mac or Linux


You can customize the speed, but not the volume or ID of the voice in gTTS,
according to the gTTS documentation; see, for example, https://buildmedia
.readthedocs.org/media/pdf/gtts/latest/gtts.pdf. However, gTTS can convert text to

10 Chapter 4
Make Python Talk (Early Access) © 2021 by Mark Liu

speech in most major world languages including Spanish, French, German,


and so on, which the pyttsx3 module can’t do. You’ll use this feature of gTTS
to build a voice translator in Chapter 16.
This script will change the default speed to slow for the gTTS module.
In Spyder, enter the following code and save it as gtts_slow.py in the chapter
folder:

import os

os.system('gtts-cli –nocheck --slow "hello, how are you?" | mpg123 -q -')

The script is the same as test_gtts.py you’ve created before except that it
adds the --slow option. This changes the voice output to slower than normal.
If you run this script in Mac or Linux, you’ll hear the computer saying,
“Hello, how are you?” in a slow pace.
Since the default setting for the speed is slow=False, and that’s what we
prefer, we won’t customize the gTTS module.

Build the Local mysay Module


In Chapter 3, you put all commands related to speech recognition in a local
module named mysr. You’ll do the same here and put all text-to-speech-
related commands in a local module.

Create mysay
You’ll create a local module mysay and save it in the same folder as any script
that uses the text-to-speech feature. That way, you can save space in the main
script. This module has adjusted the properties for speed, volume, and gen-
der of the speech set in pyttsx3_adjust.py if you are using Windows. If you are
using Mac or Linux, the local module mysay will use the default properties
in the gTTS module. You can modify these parameters based on your own
preferences.
Enter the code in Listing 4-6 and save it as mysay.py in your chapter folder.

# Import the platform module to identify your OS


1 import platform

# If you are using Windows, use pyttsx3 for text to speech


2 if platform.system() == "Windows":
import pyttsx3
3 try:
engine = pyttsx3.init()
except ImportError:
pass
except RuntimeError:
pass
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[1].id)
engine.setProperty('rate', 150)
engine.setProperty('volume', 1.2)

Make Python Talk 11


Other documents randomly have
different content
appear in all the fulness of his glory. May the God of mercy preserve
you in all temptations, and be your portion in time and in eternity.

My dear Friend,

I PRAISE God with my whole heart for your happiness and


strength, and I pray him to increase it every moment. O may
that blessed peace never leave your soul: it is eternal life begun, and
ten thousands laid in the balance with this peace would be all lighter
than vanity. It is a glorious sign, that in outward troubles, or inward
temptations, you can leave the means of your deliverance intirely to
God, without suffering your imagination to run out after the manner
in which you probably may be delivered. O that we could always
venture ourselves upon the mercies of our God! Then would he
indeed work wonders for us—wonders which we now can scarce
believe, though the God of truth himself declares them unto us. And
this God will surely keep you in the dangers to which you are going
to be exposed, if you will be watchful to keep the eye of your mind
constantly turned towards him, and wait and hang upon him, as a
little child on its fond parent, drawing all your help, all your comfort
from him, and him alone. If you have but little outward retirement,
shut more closely the door of your heart, and there in its inmost
recesses commune with your God, and Redeemer, there be
continually crying unto him—Lord thou knowest all things, thou
knowest that I love thee; thou knowest, O life and joy of my soul,
that I desire nothing but to do thy perfect will, and to be conformed
to the likeness of thy sufferings, as well as to the likeness of thy
resurrection. Oh crucify in me the whole body of sin! Give me an
humble, a mortified, and child-like spirit, and in thine own good time
perfect the work thou hast begun in my soul.

As to examples which are not good, I hope I may say, that all the
effect they can have upon my beloved friend (in her present happy
state of mind) will be to drive her nearer to her God, and in that
nearness what comfort does the believing soul find?
What tho’ earth and hell engage

To shake that soul with fear;

Calmly it defies the rage

Of persecution near.

Suffering faith shall brighter grow,

As gold when in the furnace tried:

Only Jesus will we know,

And Jesus crucified.

Yes, my love, let those who stile themselves our best friends join
with the world in calling us mopes and enthusiasts. Still stedfastly
fixed on the rock which cannot be moved, we will endure, nay
joyfully take up the reproach for his sake, who hid not his blessed
face from shame and spitting for our sakes, to make us (accursed
and lost creatures) heirs of eternal glory. Oh that his strength may
but accompany us, and the light of his countenance continually
abide with us; and then we shall not fail to go on conquering and to
conquer. Amen.

For God’s sake avoid disputes of all kinds. I was delighted the last
time you was with me, to observe that you was greatly altered for
the better in this respect. Think not that I will omit to pray for you,
and fail not to pray for me. Oh my friend, soon will time be
swallowed up in eternity.
I READILY believe you, my dear friend, that you have not brought
back the same heart you carried with you: for I thought I
discovered the two last times I saw you, a falling off from the grace
you had, and the happy state of mind you had been in; but for God’s
sake strive to recover yourself before you are sunk lower. Think how
dreadful your case will be, if you should so grieve the Spirit of God,
as to cause him to depart from you. I know your heart to be
ungrateful and deceitful, and you yourself know full well how much it
is so; but fear not to search into its most hidden corruptions. Was it
ten times more vile and polluted than it is, the blood of Jesus is all-
sufficient to cleanse it. And my dear soul, let me intreat of you
earnestly to seek after a clear and constant sense of the pardoning
love of God. This only can enable you to trample all temptations
under your feet: believe me, unless you really walk in the light of his
countenance, you never can conquer all the powers and works of
darkness. Oh seek the peace which passes all understanding. You
have need enough of it, I am sure, considering the many snares you
walk in. I really fear you do not diligently seek after God: ’tis very
certain they that seek shall find; and therefore that the Redeemer is
not fully manifested in your soul is entirely owing to your sloth and
negligence. How is it possible for you to keep your ground against
temptations which are continually striking upon your senses, unless
you have in you the substance of things hoped for, the evidence of
things not seen? When our understandings are clear in gospel
doctrines, we are too apt to imagine our hearts are so. My dear
friend, for God’s sake deceive not yourself. Oh suffer not your soul to
rest, till you can say with full assurance of faith, “My sins are
forgiven.” Depend upon it this is the first step in true Christianity. Oh
cry to God every moment from the bottom of your heart, and he will
do more for you, than you can either ask or think. I am a witness of
his free and boundless mercy. For some days past I have been in the
wilderness, my soul weary, faint, and desolate; no rejoicing in God;
not one ray from the Sun of Righteousness: but this morning, this
blessed morning, my Beloved returned to my soul, and I rejoiced
with joy unspeakable, and could say with the fullest assurance, “My
sins are done away—Christ is mine—God the Father is my reconciled
Father—God the Holy Ghost is my comforter and guide.” *Oh my
friend, my heart is now so overwhelmed I can scarce write. I could
repeat a thousand and a thousand times over—Christ is mine. My
soul is ready to spring out of its prison, and I could at this moment
face death in all its horrible prospects to go to my Redeemer. Oh
death, where is thy sting? O grave, where is thy victory? My dear
love, you know not what you lose by your negligence. O seek, strive,
agonize; could you suffer the utmost tortures in body or mind, they
would be all as nothing to gain one moment of this sweetness: and
Oh pray for me, that I may not by sinning grieve the blessed
Comforter, and lose my present peace. God be with you my dear
friend. God bless you both now and for ever.

My dear friend,
I MOURN for you, and may you mourn too from your very inmost
soul, till God himself gives you the true comfort. Oh thou dear
backslider, what shall I say? How shall I find words strong enough to
make a lasting impression on a heart so inconstant, so slothful, and
careless? Oh that the Spirit of God would assist my weak
endeavours, and point my otherwise unavailing words! You own you
do not strive earnestly: alas I too plainly see you do not. But the
blessed Comforter strives with you, and still you resist and grieve
him. How irksome is it to me always to write the same thing? My
dear soul, for God’s sake be more in earnest. How can you talk of
sloth and carelessness, when you are standing on the brink of a
precipice? Can you promise yourself another day? And are you fit to
die in the state you are now in? Nay, are you not afraid to die? Oh if
the Lord should say of you, as of the barren fig-tree, “Cut it down,
why cumbereth it the ground,” how would you be overwhelmed with
dread and confusion? For you who know so well what are the
glorious promises of the gospel, to suffer your thoughts to run upon
worldly things is inexcusable. It seems strange, that you should think
you love Christ more than you did, when you was in a better state;
however above all things hold fast, and strive to increase this love,
but then at the same time take care that you hate sin in the same
proportion, and that you strive against it with the utmost
earnestness: for to talk of loving Christ, and at the same time to give
way to sloth, carelessness, and worldly-mindedness, is an
abominable mockery. If you are encompassed with ten thousand
temptations never fear, so your own heart consent not to them. Your
blessed Master will surely help you, if you can but trust him: and
never give way, to that seeming impossibility of praying. Though
perhaps you cannot pray with comfort, or with any kind of
connection, yet if you be ever so distracted you may surely cry, Lord,
have mercy upon me—Jesus, pity me. Or even supposing you could
not do this from your heart, ask yourself whether you do not desire
to pray; and if you do, thank God for that desire, and the next
thought will be prayer. Could you not make the increase of your
family profitable, by joining at stated times of the day in some act of
devotion? If it were but for one quarter of an hour at a time, there
would doubtless be a blessing attending it. Suppose you were to
sing an hymn together, or by turns pray, either from some form of
prayer, or what would be better, extempore. You ought rather to be
silent, and be thought a mope, than to join in trifling discourse.
Consider, my love, you are to set an example to your young friends;
and fear not but God will deliver you from this bondage into the
glorious liberty of his children. The feeble trust you now have is the
work of his blessed Spirit, and he will increase it into an holy
confidence. Let not therefore your comfort sicken, but trust in that
Jesus, who died that you might live; to whose all-merciful bosom I
commit you,

And am your affectionate Friend, &c.

My dear Friend,

I HOPE your present circumstances do not prevent your constant


watching over your own heart, and pressing forward in the way
of holiness. In the midst of all these prospects death may come! And
are you fit to die? We cannot too often ask ourselves this question.
We cannot be too serious. There is only a moment between us and
eternity. May the Lord Jesus so prepare us, that at whatever hour he
calls we may be ready, our lamps trimmed, and we ourselves as
those who wait for the bridegroom. Adieu, my dear. May the
Almighty preserve you from all evil.
O F what service, my dear love, can any thing I say be of to you?
I have tried all means in my power to keep your mind more
steady but in vain. If God has at any time so blessed my letters, that
they have made any impression on you it has gone off in two or
three days: and when you have had those great benefits indeed of
conversing with living Christians, though for a time you have been
raised and lively, yet you have soon sunk into your former sloth and
carelessness. There must certainly be some hidden corruption in
your heart, which causes this inconstancy. I often study you as I
would a book, but you are in truth one of the most puzzling books I
ever met with. I often rejoice to see in you (as I think) an increase
of grace, and a decrease of that pride and selfishness, which under
an appearance of humility you once had to a great degree. The last
time you was with me, I thought you greatly advanced; and now you
are fallen again into pride and selfishness. The Lord Jesus raise you
up. Indeed, my dear soul, you grieve and wound me. You bring
sorrow in my heart, and tears in my eyes: nay and sometimes your
letters tempt me to impatience; but then I immediately recollect my
own continual backslidings, and the long-suffering of God towards
me, and can I be impatient with my friend? If your want of
retirement is not owing to yourself, never lay your coldness upon
that: for was your heart sincere, God would strengthen you at all
times to look up to him. But if as you say, you trifled away your
time, and indulged an unwillingness to prayer, no wonder God with-
held that portion of his grace he would otherwise have given you.
Depend upon it, whenever you find an unwillingness to pray, that of
all times is the most proper for you to pray in; therefore never say
on such an occasion, “I will go read some good book, or do some
good work, which may perhaps bring my mind into a better frame
for prayer.” No, do not so foolishly; but go, and prostrate yourself
before God with all your unwillingness; and he will soon give you
both the will and the power to praise him. Amen.

My dear Friend,
I T is impossible for me to judge rightly, till I know more of your
affair, and then I doubt not, but God, if we ask in sincerity, will
direct us both to agree in our sentiments, as to what will be most
conducive to your eternal welfare. However thus much I can say, be
not unequally yoked with an unbeliever. To marry a man in hopes of
making him a Christian, will be leading yourself into temptation. The
advantages you speak of may doubtless be great blessings to you, if
you are very certain you can enjoy them. You ought to be very
explicit with the person, whoever he is, both with regard to your
sentiments and his own heart. You cannot imagine the continual
snares you will walk in, if you are joined to one, who is not joined to
Christ; especially if you have any fondness for him. As in a married
state there are more allurements to draw the mind from God than in
a single one, so (if the companion be a Christian) there are also
advantages in it, which perhaps may almost make the balance even.
But how dreadful will it be, if he who should be your help, prove to
you an occasion of falling? Above all things, my dear, try the sincerity
of your own heart. Examine well whether you can accept this offer
with a single eye to the glory of God, and the good of your own
soul; and fear not, if you ask counsel of God in faith nothing
wavering, that he will give you freedom of mind, either to accept or
refuse as will be most profitable for you.

I do not wonder that your soul is at present distracted with


worldly thoughts. An affair of this kind always occasions a thousand
distractions, especially where it is in suspense. I fear your increase
of company does not at all add to your spiritual happiness. The Lord
Jesus bless you: I pity you. What need have we of continual
assistance from above? How do we walk as on burning coals? O let
us strive for that state of mind, in which we can say, nothing gives
me pain but what is contrary to the will of God, and tends to draw
my soul from him; and nothing gives me pleasure, but as it is
agreeable to his will, and tends to draw my soul nearer to him.
Amen.
My dear Soul,
I AM glad to write to you once more under the name of ****, and I
hope God will give me strength to say all I wish at this
important juncture. Important it is indeed to you; and the nearer the
time approaches, the more I feel for you. Alas, you are now plunging
into difficulties, which you can have no notion of until you
experience them. You will have need of more than double
watchfulness. Oh cry earnestly to God for grace and strength to
keep your soul from sinking under the delusive arguments, which
your three grand enemies, the world, the flesh, and the devil will be
continually attacking you with in your new state of life. You know,
my love, in all our intercourse, I have not failed to set before you the
disadvantages and distractions you must necessarily meet with in a
married life. This I thought it my duty to do, though your intentions
in regard to marriage were always founded upon Christian motives.
Had I found you inclined to dedicate yourself more particularly to
God in a single state, I should doubtless have encouraged that
inclination; but as this was not the case, and I did not dare
absolutely to dissuade any one from marrying, I have therefore only
strove to guard you against the evils attending that condition, and
pray God grant you may find them overbalanced by the good. The
first evil, which people are apt to fall into when they marry, is an
extreme selfishness: this I have seen most flagrant instances of, but
then the people were not Christians. Oh my friend, remember you
have taken upon you the sacred name of Christian. The next thing
which our sex in particular is very subject to, is a pretty indolence of
soul, and a kind of hugging themselves as though they were become
people of vast consequence; and then all they say or do, and every
thing which belongs to them, is of importance. You will think
perhaps there is no danger of your falling into any thing so low and
silly as this; but do not think so, for without extreme watchfulness it
will steal imperceptibly upon you, and if you once grow important,
the flood-gates of worldly-mindedness will be set open, and your
faith, your love, and peace, will be borne away by the impetuous
torrent. The Lord Jesus bless you and keep you, and grant that in all
the changes of this mortal life, your heart may there be fixed where
true joys are to be found.
Your ever-affectionate

****

My dear Friend,

I KNOW not how to assume to myself the character you mention,


and yet I dare not neglect to do any thing, which you tell me
may be of benefit to your soul. I know God can convey blessings by
the meanest instrument, and relying wholly on his power and
goodness, I enter again into this correspondence. You complain that
I have not lately been so watchful over you as usual: In writing I
certainly have not, and you know the reason; but as to speaking, if I
have there failed, it is entirely owing to my being so apt to think
highly of you. I fear in this I may have dealt with you as with my
own heart—judged too favourably of both. May God give me a
clearer insight both into you and into myself.

*I doubt not but your present condition contributes greatly to


your being more in earnest, and you have need to lay up all the
strength you can against what may be a time of trial indeed. I am
glad you found such a blessing on Sunday. I doubt not but the
greater degree of light and joy you have, the more you will be
assaulted by temptations, and these perhaps not only of a strange,
but also of an impertinent and ridiculous kind. The devil will
sometimes play the buffoon: but I have found the best way of
dealing with these temptations was not to combat them, but to let
them pass through the mind, as you would let a troublesome croud
of people pass by your door without regarding them.
*The speaking evil of your neighbour before you are aware,
though it has not all the blackness of premeditated evil speaking, yet
it is a sure sign, that you have not that spirit of love, without which
the highest attainments are but as sounding brass, and as a tinkling
cymbal. I often am sorry to see how much this divine temper is
wanting amongst religious people. For my own part, I stand self-
condemned in this, though it is a sin, which I have even a natural
aversion to; and I fear there are but few hearts in which this root of
bitterness does not grow almost imperceptibly. However, the Captain
of our salvation can give us to tread even this enemy under our feet.
Let us therefore go on, nothing discouraged, trusting in his help, and
following his steps, until we apprehend, that for which we are
apprehended of this divine leader.

Your ever affectionate and faithful, &c.

My dear Friend,
* R. V. has desired me to meet Dr. **** at his house; but though I
M honour the character of that worthy man, yet I rather fear,
than desire to do this. I really now dread the being set up as
something to be thought well of. I see such a depth of pride and
self-love in my own heart, that I dread any thing, which can give the
least food to these hellish tempers. I am well satisfied, that there
can be no perfect peace, no perfect love, till these be done away.
Was not the blessed Jesus meek and lowly of heart? Was not he
despised and rejected? And we? Oh, my dear love, tremble for
yourself and for me. We are esteemed, admired, and sought after.
Do we not, think you, tread upon burning coals? How dangerous,
how difficult to act for the glory of God, without sacrificing
something to self? And this self is all that separates from God—this
self is all that keeps the blessings both of time and eternity from our
souls. Oh let us learn, and know and feel, that we are nothing, and
that God is all in all. Certain it is that unless we die with Christ, we
cannot rise to his life. Unless we are crucified with him here, we
cannot reign with him hereafter. Let us then nail our corrupt nature
to his cross, and continually mortify every temper that is contrary to
his perfect will. Suffer we must; but the love of God will make all
sufferings sweet, and his grace will enable us to conquer all
difficulties. I rejoice at the victory, which you tell me has been given
you over (I suppose) some reigning sin. Is not this encouragement
to press forward? If you would preserve constant peace and
recollection, look more into your own heart, and lay not out yourself
too much upon others. I have seen so much of the ill effects of this,
that I dread it both for you and myself. Watch continually.

Your ever affectionate, &c.

****
Y OUR letter, my dear life, has given me great pleasure. This is
indeed, as it ought to be. And Oh by no means suffer this
anxious desire after God, this thirst after holiness to abate; only let it
be mixed with that kind of resignation, which implies a willingness to
suffer, so you may be kept from sin. The pain you speak of I rejoice
in. Oh my love, this is right; and may you more and more be
conformed to Jesus Christ, and him crucified. A soul thus pained,
thus longing, thus struggling for salvation, and at the same time
lying low at the foot of the cross, and crying, “Lord thy will be done,”
is an object in which the holy angels rejoice, nay on which God
himself looks down well pleased. To such a soul every gospel
blessing is near at hand. The Sun of Righteousness is on the point of
rising in it with healing in his wings; the eternal Comforter is ready
to witness with it, that it is born of God, and to fill it with that peace,
which passeth all understanding. The blessed and adorable Trinity is
ready to raise it from its fallen state, and to perfect the new
creation. What encouraging prospects! Only let not this happy pain
be taken from you by any comfort the world can give, but hold it
dear to your heart, as light to your eyes, till God himself change it to
joy unspeakable.

*I have long thought that to wish for any thing, but the salvation
of our own souls and that of others is wrong: because in nothing
else can we be sure that our wishes are agreeable to the will of God.
I do not know how to believe, that you could wish for more riches;
and if the being pleased with the thoughts of gain proceeded only
from this motive, that you thought God was putting it more in your
power to relieve the necessities of others, I would not dare to
condemn you: but it is so difficult to take any satisfaction of this kind
without some mixture of worldly-mindedness, that we cannot be too
careful in this respect; nay we ought rather to fear lest we should
not be found faithful stewards of the talents put into our hands, as
knowing, that both in spiritual and temporal blessings, “To whom
much is given, of them shall much be required.”
My dear Friend,

I F it should please God to make any thing I write of benefit to your


soul, I should greatly rejoice, but without that my words will
avail nothing. And really the account you give of yourself at present
is so strange, that I know not how to speak to you, or whether
harshness or love is most necessary. This I know, that my own soul
is greatly pained for you, but I dare not flatter you, “If any man hath
not the Spirit of Christ, he is none of his;” and doubtless to take a
pleasure in exposing the faults of others is a temper as distant from
the Spirit of Christ, as hell is from heaven. *Believe me, my dear life,
if the love of God reigned in your heart, you would rather cover than
expose the faults even of the vilest of men. And when obliged for
their own good, or the warning of others, to speak to the
disadvantage of any one, you would do it with fear and caution, at
the same time looking up to God, lest any bitterness should mix,
either with your thoughts or words. God is love, and infinite streams
of love are perpetually flowing from him through all created nature.
His acts of judgment as well as mercy are only acts of love, and
designed either to remove or to lessen the evils occasioned by the
fall of angels and of man; and the soul which is born of God will as
necessarily partake of this divine principle of universal love, as the
child you now carry within you partakes of your corrupt nature. You
have great reason then to tremble, while this temper has any footing
in your soul. Don’t sit down contented, because you have intervals of
recollection, but wrestle mightily with God in fervent prayer, until he
speak peace to your soul, and his love be shed abroad in your heart,
before which this evil disposition will fly as a mist before the morning
sun. You greatly affect me by what you say in regard to the
expected hour of danger; but fear not. No creature on earth can be
more unworthy than I am; and the God of mercy protected me, and
gave me strength, and courage, and calmness; and I doubt not but
he will shew the same mercy to you: nay I have a strong confidence
he will in your hour of extremity give you a clearer sense of his
pardoning love, than you have yet experienced. Fear not, only
believe, “All things are possible to him that believeth.”
It has pleased God within these few days to give me a severe
trial, and eternal glory be to his name, I have stood it, crying only,
Lord, thy will be done. My little boy was taken on Saturday evening
with strong convulsions, and between that time and Sunday evening,
had I believe, full forty fits. He is now much better. God is ever
merciful: he brings to the borders of the grave, and raises up again.
O how good it is to suffer? How glorious to have grace triumph over
nature? How sweet to lay low at the foot of the cross, and bless God
for every thing which more conforms us to the suffering Jesus? Be
watchful, and earnest. Adieu.

My dear Friend,
*
WHERE the consideration of the prophecies is a means of stirring
any one up to greater diligence, or making them sit looser to
the things of this world, and seek more earnestly after the things of
God, they cannot consider them too attentively. Every soul should
carefully observe that way, in which God particularly leads it, and
punctually follow every means which it finds by experience brings it
nearer to God. Some are awakened and brought low by meditating
on the severe judgments of God; others are melted down by
reflecting on his mercies. Some are employed usefully to themselves,
and it may be to others, by accurately considering the several
amazing dispensations of God in the whole scheme of our
redemption. Others by a more simple and general view of God, as
infinite wisdom and infinite love, rest calmly on his will, and though
in a lower and less shining way, pursue the same end, viz. salvation
by the blood of the Lamb from the power as well as from the guilt of
sin, and union with the pure fountain of all happiness. All these ways
are good in themselves, and are made so to every soul, which in
them follows the leadings of the Spirit of God. But I may make that,
which is good in itself, evil to me, by using it only because another
thinks it right, and not because I find it the means which most unites
my soul to Christ; and therefore we ought never to blame any one
for not being affected by that which affects us.
’Tis very certain that the judgments of God are now abroad in
the earth, and that some of the signs of the last times plainly
appear; this (whether the calculation in the letter be right or wrong)
is obvious to every one, and calls aloud for seriousness and
watchfulness. Happy are those who shall stand unmoved in the time
of temptation. Happy are those who when all nature is agonizing
around them can fly to the only rock of refuge, and there find
shelter from the storm, and shadow from the heat. But above all
happy are those, who shall have the glory of suffering for their
Redeemer, of sealing their testimony with their blood, or in the midst
of the fire shouting for joy, and blessing God for a martyr’s crown.
These, these are glorious prospects, and weak as we are, should
God honour us with a trial like this, he would also give us strength to
be more than conquerors. In the mean time let us not be weary or
faint in our minds, but manfully fight till we obtain complete victory
over our evil hearts; and then shall we stand with humble
confidence even before our judge, and though all nature was
dissolved, we should remain unshaken, and be wholly swallowed up
in joy full of glory. Amen, Lord Jesus.

My dear Friend,
* THANK you for your last letter, and I bless God, that you was not
I offended at mine. This bearing of plain-dealing is a comfortable
proof to me of your sincerity. If temptations increase, God will give a
proportionable increase of strength. There wants nothing but
faithfulness on your part to the grace already given. I know not the
particulars of your sufferings, but I know it is good to suffer. It is a
discipline all must go through, who make any tolerable advance in
the school of Christ. I could wish you to seek more after religion,
than comfort. Constant and heart-felt resignation is a bulwark
against every trial, and a foundation for solid peace, and joy
transcendently pure. The whole state of a soul made perfect in love
stands in that one petition, Thy will be done: and if we could but
preserve that temper which these words describe, I know not what
could hurt us. Suppose now when I first wake in a morning I should
lift up my heart, “Lord I bless thee for this new day which thou hast
given me. In this day I shall have fresh manifestations of thy will
concerning me, either in comforts or in sufferings. Lord, I am thy
creature, deal with me as it shall please thee: only leave me not to
myself, but let thy grace be sufficient for me, and thy strength be
made perfect in my weakness.” When settled in this frame of mind,
suppose my trials to begin. I am tempted by the perverseness and
evil tempers of my own family to impatience, to anger; but I
immediately recollect myself, “Lord it is thy will I should bear this;
pardon their perverseness, and give me to be thankful for every
opportunity of self-denial and forbearance.” Well! now another, and
more difficult trial appears. I am to behave to people, whom I know
to be my bitter enemies, whom I know to be continually seeking
occasions of evil against me, as if they were my dear friends. Here
every faculty of the soul is alarmed, and nature shrinks back
affrighted. But what does grace say? “Lord I thank thee for this
glorious trial! What a blessing is it I should be permitted to drink of
the same cup my Saviour drank of! Oh bless these mine enemies; fill
their hearts with thy love; let thy will be perfected both in them and
me.” This temptation is conquered, but another and a more trying
one immediately succeeds. I am treated unkindly by people I love,
and who are really my friends. Here my heart is wounded, it sinks, it
is ready to faint; but recovering itself it rests upon God, and says,
“Lord, even in this, thy will be done, and let the sufferings of Christ
be perfected in me, that I may be also a partaker of his glory.” In
this manner one might instance in all kinds of affliction, and find
comfort and strength in each.

I know not how to think so meanly of you, as to imagine your


heart in danger of being drawn away by the world. But I know I am
always apt to set you in too high a light, and it may be so, in this
case; this one thing however I am sure of, that we are fighting for
eternity, and this against innumerable enemies, dangerous ones
without, but far more dangerous ones within. If the Lord himself was
not on our side, how could we maintain our ground one moment. To
his almighty protection I commend you and yours, and am

Your ever-affectionate, &c.

To the Rev. Mr. ****.

Dear Sir,
I AM much obliged to you for your kind concern on my account. My
illness I believe is rather troublesome than dangerous, a
disorder in my stomach, which has been attended with a slight fever.
I was ill, when you and Mr. **** were to see me though I did not
complain, and I looked upon it as a particular blessing: for had my
spirits been in their full flow, an event so much wished, would have
too much elated me: but my disorder served to keep the balance of
my mind even. I see the goodness of God to me in every thing, and
therefore sickness or health, life or death are equally welcome to
me, as coming from the same gracious hand. Nature, its true,
shrinks at suffering, but grace triumphs in resignation, and is
thankful for the dispensation of the present moment, without
wishing or willing in regard to the future. But I hope to learn some
lessons of this kind from you next Sunday. Till then farewell, and
may the fulness of every gospel blessing rest upon your soul.

Your’s, &c.

****

Dear Sir,
T HE judgments of God upon Lisbon are dreadful indeed. I know
not what heart can be hard enough to hear of them without
concern. What but the amazing mercy of a long-suffering God can
prevent London from feeling the same dreadful blow! And if God
should arise to shake terribly our land, what great reason will those
persons have to be thankful, whom God has drawn from all worldly
schemes of happiness, and fixed their hearts on a basis, which can
never be shaken, though the earth be moved, and the mountains
cast into the midst of the sea? I have been much comforted in
respect of the miseries of others by this scripture—When the
judgments of God are abroad in the earth, the inhabitants thereof
will learn righteousness. If such a blessed end is produced by these
severe acts of justice, have we not reason even in the midst of terror
to admire and adore? The whole universe appears to me to be in the
hand of God, as a grain of dust in the balance; and I, a creature
more insignificant, more worthless, and sinful than can be
conceived, am among the rest in this almighty hand, and all is safe.
My heart is by nature painfully tender, and yet in the midst of
feeling, either for myself or others, there is a secret satisfaction in
my inmost soul, that God is glorified in every act of his providence,
whether of judgment or mercy; and I hardly know how to form any
other prayer than Thy will be done.

I fear I shall not see you on Thursday;――but wherever you are,


may the God of all consolation be your light and your shield, and
bring you safe to that city, which has eternal foundations.

I am your ever-obliged friend and servant, &c.


* Y what you said to Mr. **** when he had the pleasure of hearing
B you, I imagine you think my illness is owing to a cause of which
I am by no means certain; however the bare probability of such a
charge would not be without my immediately reflecting on the
dangers and temptations that would attend it. A soul, that is really
desirous of attaining the pure love of God, is exceedingly jealous of
any thing that has a possibility of drawing it from its centre of
happiness, and looks upon any event which has this possible
tendency (let the world term it blessing or misfortune) with a tender,
anxious fear, which none can understand but those who have felt it.
This was my case, and my imagination would sometimes paint a
thousand instances which might draw my soul down to earth. And
this fear (though it never made me wish any thing but what was the
will of God) would bring the tears to my eyes, and cause an
uneasiness, which doubtless proceeded from want of faith. But that
God whose mercies are renewed every morning, soon delivered me
from those fears, and calm peace, perfect resignation and
watchfulness succeeded. And for this fortnight past, though I have
been in continual uncertainty, whether I should continue in the
condition I am thought to be in or not, my mind by the all-sufficient
grace of God has been so equally kept, that I have not had the least
wish or choice of my own, but have been equally pleased with
whatever seemed to be the leadings of Providence concerning me.
And you cannot think, what a work of annihilation this uncertainty
has been the means of carrying on in my soul, which I see plainly in
the nature of things could not so well have been effected by any
other. I never can be enough thankful for the unspeakable mercies
of God to so unworthy a creature. My will has been brought into
deadness, which I, even a few months ago, should have thought
almost impossible; and I see, and have some foretastes of that state
which is called the pure and disinterested love of God, in a manner I
cannot express.
I should be very glad to see you when your affairs will permit, for
I have not had one help from without since I saw you last; nor have
I had many of those joys and comforts from within which have
sometimes been indulged me. And indeed my animal frame would
have been too weak to have borne them, unless God had in a
particular manner supported it: for every faculty of my soul has been
weighed down by continual sickness. I have not only been incapable
of any outward application, but also of intense thinking or fervent
prayer. But in the midst of this my weakness, the strength of God
has more abundantly been made manifest, that I might be abased
even to the dust, and his free grace exalted; so that I well
understand what St. Paul meant, when he said, Therefore will I glory
in weakness, in distresses, that the power of Christ may rest upon
me.—But I must finish this already too long letter. Farewell! May the
dew of heaven continually refresh you!

****

January 19, 1756.

Dear Sir,

I AM much obliged to you for your letter, from which I have learnt a
very useful lesson, viz. Never to fancy that the particular
circumstances of others would be more advantageous to me than
my own. You are ready almost to envy me my many hours of
retirement; when at the same time, I am continually complaining
that I have so few, and often crying out, when shall I have a whole
day to myself? And then I frequently think, were I a man and in the
ministry, my time would then be all spent for God; but now, what an
inundation of trifling flows in upon me, which ’tis impossible for me
to avoid, without altogether going out of the world.
I enter upon the subject, on which you bid me write with fear
and trembling. My abilities are really far from being equal to it: for
although I know many Christians, who would immediately cry out,
that it needed not one moment’s consideration, I dare not do so; for
I now really feel the weight of it upon my soul. *’Tis a most alarming
truth, that a minister may speak with the tongue of men and of
angels, and that the power of God may so accompany his words as
to make them the means of converting thousands; and yet for want
of duly searching into his own heart, he may suffer it to be
overgrown with poisonous weeds, with tempers and inclinations,
which if unsubdued, will absolutely shut him out from the kingdom
of glory, to which he is leading others. How easy for a man who is
continually setting forth the glorious truths of the gospel, and
inforcing holiness of heart and life, to imagine (for want of constant
self-examination) that he himself is what he preaches? This is a
most dangerous snare; and therefore how absolutely necessary is
that retirement which affords opportunity for a diligent search into
the recesses of the heart, and gives the soul leisure to wait in awful
silence before God, where, free from every object of sense, and from
the workings of imagination, it may with all its faculties prostrate
before the eternal Trinity, and feel itself to be nothing, and God to be
all in all? But then it may be asked, shall not a man who with
singleness of heart, spends and is spent for the service of God, be so
kept by divine grace, that his soul shall suffer no loss by the want of
retirement? Doubtless. Where sincerity and singleness of heart are
preserved, that soul shall be defended as with a shield. But this I
take to be the grand temptation of every minister of the gospel; he
sets out perhaps (though this is not always the case) with a single
view to the glory of God and the salvation of souls. The power of
God accompanies his words, the hearts of the people fall under him.
His reputation daily increases, till at last he becomes popular. He
sees himself surrounded by a croud of people, who for the most part
hear him as an angel of God, their thirsty souls gasping after the
truths he utters. An innocent and an holy joy fills his heart; “Here
are souls that may be won to Christ, and that by me! Lord, what
amazing love, that I who am the least of all thy servants should be
thus blest!”—So far all is well, all is happy: but the subtil enemy of
mankind so strongly impresses this, by me, that a self-complacency,
separate from the glory of God, arises in his heart, and this, if not
immediately quelled, leads him to the brink of a precipice. God still,
for the sake of others, continues his usefulness; but every
conversion which he is the means of making, is fresh food for his
self-love; and by degrees he becomes so dead to the love of God,
that he preaches even the purest doctrines of the gospel, with the
same spirit, with which a lawyer pleads at the bar. But on the
contrary, that blessed servant of Christ who stedfastly pursues the
narrow path, who conquers every rising of self-love in its first
appearance, and constantly refers all the good he does or speaks to
the author and giver of all good, he shall be kept in all his ways, and
blest in all his works. And though his soul may pant for retirement,
as thinking he should there enjoy nearer communion with God, and
make higher advances in the divine life, this may not perhaps be
immediately permitted him: but in order that his future crown may
be the brighter, God may make his present usefulness a sure sign to
him, that he ought to continue his constant labours for others,
though it should be with much temptation, fear, and trembling.
However this is very certain, that God to a servant thus sincere, will
point out a plain path, either by inward leadings which cannot be
mistaken, or outward providences.—Adieu! Pardon the weakness of
this; let me see you the first time you have to spare, and believe me

Your ever obliged and affectionate servant,

****

Dear Sir,
W HATEVER the Spirit of God makes useful to my heart, either
from scripture or from spiritual authors, I thankfully receive,
and give him the glory: but I well know there is but one great touch-
stone, by which all doctrines are to be tried; and therefore I hope
your kind fears for me, lest I should not enough esteem the written
word of God, are needless. I am so far from setting any human
writer on a footing with this, that I scarcely read them at all, i. e. in
comparison of my bible. I look over some few, but this is very
different from the manner of reading you recommend, and which I
strive by the grace of God to practise; nay, it would be the greatest
slavery to me you can conceive, if I were obliged to read many
religious books: however I return you the sincerest thanks for your
care, and beg you will in all things watch over me with a “godly
jealousy.”—But my dear friend, could you imagine that I enquired
after the state of your mind according to the common acceptation of
the word? I only desired to know what spiritual blessings you had
both from without and within, that I might share them with you. And
this I was emboldened to do by the sweet account you had given in
your former letter, of the blessings you enjoyed at Bristol. The Lord
refresh your soul continually with the rich streams of his redeeming
love, and may his everlasting arms be beneath you! I know your
present state, of hanging as it were in suspence between the visible
and invisible world, is a dispensation big with divine love. And was I
to pray for you that prayer which my soul most loves, it would be,
“that you should lie in the hand of God as an instrument, without
choice, till the will of God was perfected in you.” This would be the
prayer of pure love and enlightened faith; but if I descended to the
tenderness of friendship, I should ask your speedy recovery. If it
should be given me to see you again in this world of vanity and woe,
I shall be thankful, and perhaps it may be so: but I know not—
something seems to whisper me that the thread both of your life and
mine is nearly spun. For my part, I have within these few days had a
sweet call to eternity, by a sudden and violent disorder in my
stomach and bowels (called according to the fashionable phrase a
nervous cholick) which seems to have set me a good way forwards
on my journey. Happy pain! Kind messenger! O my friend, I have
nothing but mercies to tell you of. So supported! Such wonderous
grace! Such boundless love! I all sin and misery: the Saviour all
tenderness and mercy: the probable approach of death delightful: no
sting remaining. No clog upon my chariot-wheels. Mercies too from
without which I had never before experienced in a time of sickness.
The Rev. Mr. **** praying and singing by my bed, with such power
of faith and love, such unction from above! Does this hurry the
spirits? Does this endanger? How far from it? I protest not only my
soul rejoiced, but even my body grew better as he prayed. Do not
fail to thank God on my behalf, and pray for me that I may not be
ungrateful to such amazing mercy. May the Lord Jesus preserve you,
sweeten every pain, and make you rejoice continually with joy
unspeakable and full of glory.

Your ever-affectionate and obliged friend,

****

June 7, 1756.

June 15, 1756.

Dear Sir,
Y OUR very kind letter has pained me extremely, but I hope it has
been made a means of humbling my soul before God. How
little do I deserve that you should write to me in this manner? Alas
you do not know me; I am less than the least of all the mercies of
God; do not, I beseech you, think so highly of me; it really makes
me ashamed of myself. Oh that I could be lower than the dust! Oh
that I could shrink into nothing at the presence of my God! The way
too in which you speak of yourself, puts me in a strange dilemma, I
dare not pay religious compliments, and yet how shall I write to you,
as if I believed you? How much greater has your cross of sickness
been than mine? So long, so lingering, such inconveniences as it lays
you under. But yet this is certainly no excuse for a soul, taught of
God, as your’s is, to wish its removal. *Did you indeed wish for any
thing but sanctification? Surely, my dear friend, you wrong yourself;
it cannot be. Oh remember the glorious path you have often pointed
out to me, of perfect resignation! I have considered you as a pattern
to me, particularly in this. I must not think that you have any
“reluctance to bear the cross;” it would wound my heart too much.
Do I not know, that you love God above all things? Do not I know
the sincere desires of your soul after holiness? And is there any way
in the spiritual life, which so immediately leads to holiness, as willing
suffering? Happy are those to whom God gives the grace of doing
much for him, for his cause, for his people; but ten times more
blessed are they who suffer with Christ. Is there a joy absolutely
pure? It is that of suffering. Oh did we but know the health, the
peace, the life that is at the bottom of every bitter cup; with what
alacrity should we drink it? With what thankfulness, nay, with tears
of joy, should we cry, Lord, what unbounded mercy, what
astonishing grace is this, to a worm like me; that I should be led in
this most excellent way; that I should be made to tread in those
footsteps which are most eminently thine? Dearest Saviour, sweet is
thy cross, sweet is thy thorny crown; thy stripes, thy wounds, thy
pain, more delightful than beds of roses. Let other souls glory in
mount Tabor; my joy shall be to stay with thee on mount Calvary,
that I may be made conformable to thy death. Such would be the
language of a soul truly sensible of the great benefit of suffering,
and embracing, with sweet complacency, the cross, which thus
united it with its Redeemer. May this be the language of your soul
and mine; then shall we be found unshaken in the fiery trial, and
come out as gold purified seven times. But after all, what suffering
have I had in this illness? It can scarce be called suffering, when
God sensibly supports. The suffering is when he leaves the soul (as
it were alone) in pain or in affliction, to struggle with the powers of
darkness, which at such a time eagerly beset it. This I have
sometimes known, and this is suffering indeed.—I have the same
confidence in God for my dear Mr. ****, that you have. Was I to be
removed, I doubt not but it would be made a means of good to his
soul; but it seems at present to be the will of God that I should
continue some time longer. My inward weakness is not so great, and
my pain, though pretty constant, is so slight, that it is scarce worth
the mentioning. I thank God that your health is returning, and trust
we shall meet again on this side the river; but in the mean time pray
earnestly for me. I fear ease more than pain. Farewell! May you and
I constantly join in this prayer, “Thy will be done in us, and by us, in
time and in eternity!”

Your ever-obliged and affectionate friend,

****

July 1, 1756.

My dear Friend,

You might also like