Speech to speech in python [text to speech]

Let's speak voice

environment

ubuntu 18.04 python3


Speak Japanese

You can speak Japanese with OpenJtalk, the following Qiita is easy to understand. Speak Japanese text with OpenJTalk + python


Speak english

Voice utterances in English introduce espeak and svoxpico.

espeak

Install the environment with the following command.

$sudo apt-get install espeak

Operation check

python


from subprocess import call
call(["espeak","hello world"])

svoxpico

Install the environment with the following command.

sudo apt-get install -y libttspico-utils

Operation check Caution! The file name is module_pico.py, If you create it with another name, it will not work unless you change the # Define path part.

module_pico.py


import os
import subprocess
file_path = os.path.abspath(__file__)

# Define path
speech_wave = file_path.replace('/module_pico.py', '/speech.wav')

def speak(content):
    print("[*] SPEAK : {0}".format(content),flush=True)
    #subprocess.call('amixer sset Master 90% -q --quiet', shell=True)  # big voice
    subprocess.call(['pico2wave', '-w={}'.format(speech_wave), content])
    subprocess.call('aplay -q --quiet {}'.format(speech_wave), shell=True)
    #subprocess.call('amixer sset Master 75% -q --quiet', shell=True)  # default voice

if __name__ == '__main__':
    speak("I like apple!")


When using it as a module, you can speak in the same folder as follows. You don't have to worry about the file name.

test.py


import module_pico
    module_pico.speak("I like apple!")

Recommended Posts

Speech to speech in python [text to speech]
Clustering text in Python
English speech recognition with python [speech to text]
Text processing in Python
Speech recognition in Python
tse --Introduction to Text Stream Editor in Python
I implemented Google's Speech to text in Django
UTF8 text processing in python
To flush stdout in Python
Login to website in Python
How to develop in Python
Post to Slack in Python
Python OpenCV tried to display the image in text.
[Python] How to do PCA in Python
GOTO in Python with Sublime Text 3
Convert markdown to PDF in Python
How to collect images in Python
How to use SQLite in Python
In the python command python points to python3.8
Try to calculate Trace in Python
Extract text from images in Python
Sort large text files in Python
How to use Mysql in python
How to wrap C in Python
6 ways to string objects in Python
How to use PubChem in Python
Reading and writing text in Python
How to handle Japanese in Python
An alternative to `pause` in Python
Convert Excel file to text in Python for diff purposes
Python in optimization
CURL in python
I tried to implement PLSA in Python
Metaprogramming in Python
Updated to Python 2.7.9
[Introduction to Python] How to use class in Python?
Python 3.3 in Anaconda
Geocoding in python
I tried using Azure Speech to Text.
Try logging in to qiita with Python
Install Pyaudio to play wave in python
How to access environment variables in Python
I tried to implement permutation in Python
Method to build Python environment in Xcode 6
Meta-analysis in Python
How to dynamically define variables in Python
How to do R chartr () in Python
Unittest in python
Pin current directory to script directory in Python
[Itertools.permutations] How to put permutations in Python
PUT gzip directly to S3 in Python
Send email to multiple recipients in Python (Python 3)
Convert psd file to png in Python
Sample script to trap signals in Python
Epoch in Python
Discord in Python
Decorator to avoid UnicodeEncodeError in Python 3 print ()
How to work with BigQuery in Python
Sudoku in Python
DCI in Python
quicksort in python