speech intelligent voice module proper way to | practice learning Python

Recent life, learning the rhythm is very easy to be interrupted, finally, after today, either end of the internship, summer camp is over.

A few days ago, a man in the review to be tired when the Python again picked up, saw a lot of knowledge. Really interested in (wu) Si (liao) up! Here. The way for everyone to recommend a very full resources of the non-free learning python skirt answer: Seven Yiyi nine hundred seventy-seven bar and the next five (digital homonym) conversion can be found, there is a senior programmer before learning to share experiences, study notes, there are front-line experience in business, and for everyone to carefully organize a python to combat zero-based information projects, python day to you on the latest technology, prospects, learning to leave a message of small details

Environmental ready
1️⃣ python2. * Or python3. *

2️⃣ install extensions pywin32

3️⃣ installation speech module

Install Python 2/3
two are fitted or installed Python2 choice Python3, I personally recommend, a little more than step switching environment variable when used in certain places only.
Of course, I think that the length of the current Python3 has launched perspective, beginner, then it is recommended that you choose to install Python2 familiar with some of the grammatical structure of the definition of Python, and use some of it to be more comfortable.
After all Python2 launch time a bit longer, I encountered some problems, search for solutions is also more abundant; the same time, ah, so that there is still part of the module function can not adapt Python3 Python3 * or higher version.
Specific installation process on unknown talked about, no matter which version is almost similar, very easy to use is one of the features of Python
after installing Python environment ah, after all, is a programming language, choose a suitable IDE is essential here, I recommend reading about Python IDE, more Python IDE see: HTTP: //wiki.python.org/moin/PythonEditors
PyCharm IDE
many IDE, most everyone is a sought after PyCharm, and as part of the family bucket of JetBrains, the software has perfect features, such as: debugging, syntax highlighting, project management, code branches, IntelliSense, auto-complete, unit testing, and even version control. In addition, it offers some nice features for Django development, and support Google App Engine, cooler is that, PyCharm support IronPython.


Official Download: http: //www.jetbrains.com/pycharm/download/

IntelliJ IDEA License: http: //idea.lanyus.com/ and break the help documentation provided

IDEA series theme download address: http: //www.riaway.com/theme.php, supports IDE includes these topics: InteliJ IDEA, PhpStorm, PyCharm, RubyMine, WebStorm and AppCode.

Note: how to install the downloaded theme

From the main menu you open the editor choose File-> Import Setting, select the files you download jar;
configure after waiting for the restart: Open File-> Settings-> Editor-> Colors and fonts, and then select the theme you can install carry out.
Pywin32 install extensions
pywin32 namely Python for Windows Extensions, provides the interface to access and invoke Windows Pyhton underlying performance function, pywin32 including win32api, win32com, win32gui, win32process modules

Download: https://sourceforge.net/projects/pywin32/files/pywin32/Build%20221/

According to this version of Python (2. * / * 3) bits and a CPU (32-bit / 64-bit), download and install the appropriate version.


For example, I like this situation, you need to install pywin32-221.win-amd64-py3.7.exe


Installation speech module
to use pip install speech commands to install, but a user's Python3 for installation, but also for some of the new features Python3 of the configuration file after installation to make some changes

As pip here, it is the Python package management tool that provides a Python package to find, download, install, uninstall function;
at the same time, Python 2.7.9 + and Python 3.4+ version comes with pip above tool, as long as when the installation did not uncheck that option, generally do not have to install a special, can be judged by the command pip --version has been installed;
PIP official website Download: https: //pypi.org/project/pip/, note which version of the Python run the installation script, pip was linked to which version;
it is worth noting that some Linux distributions directly with your package manager to install pip, such as Debian and Ubuntu: sudo apt-get install python -pip .

pip common instruction related
function instruction
version and pip path --version
get help pip --help
upgrade pip pip install -U pip
install the latest version of the package pip install SomePackage
install the specified version pip install SomePackage == 1.0.4
minimum version pip install ' somePackage> = 1.0.4 '
upgrade package pip install --upgrade somePackage
upgraded to use the specified package ==> =
unload package pip uninstall somePackage
search packet pip search somePackage
shows the installation package information pip show
details specified package pip show See -f somePackage
List installed packages pip list
view can upgrade package pip list -o
Note: If the above problems with the upgrade pip command, you can use the following command: sudo easy_install --upgrade pip

Python3. * Under normal environment using the workaround speech of
speech's Project description

After installing the speech modules, speech.py ​​need to modify the file, the file path .. \ Python37 \ Lib the \ site-packages

line59 修改import thread,改成import threading;
line157 修改print prompt,改成print(prompt);
对最后的函数_ensure_event_thread修改如下:
class T(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
pass

def _ensure_event_thread():
"""
Make sure the eventthread is running, which checks the handlerqueue
for new eventhandlers to create, and runs the message pump.
"""
global _eventthread
if not _eventthread:
def loop():
while _eventthread:
pythoncom.PumpWaitingMessages()
if _handlerqueue:
(context,listener,callback) = _handlerqueue.pop()
Creating the Just A _ListenerCallback Object # Makes Events
# Fire Till listener LOSES Reference to the ITS Grammar Object
_ListenerCallback (context, listener, callback)
the time.sleep (.5)
_eventthread = T ()
_eventthread.start ()
intelligent voice automatically read the script word
before a few days, a friend gave me a file on computer-related professional English vocabulary, after receiving has been placed on the desktop, I do not know there is no use.

This afternoon, when, because of the recent summer camp activities have been and AI-related research team communication, so suddenly thought of Can these English words with the existing Python extension package to implement a voice similar to "classroom spelling" of automatic (not to mention intelligence) mode.

Specific source code below can also see the entire program structure is very simple, did not spend much time, I believe it is also not difficult to understand.

It should be noted there are so few points:

The sample words are provided computer-related professional, if you want to be replaced by another word, only need to modify test.csv files. Which, test.csv There are two data files, representing the English vocabulary with the corresponding Chinese interpretation, the English translation of the functions in order to achieve, as long as these to swap the order of the columns to click.

And "classroom spelling" mode similar, each will be separated by Interval_Time time in a row the voice output vocabulary twice (dictation, the general teacher will intervals with read 2 or 3 times), after the words, each dictating a small group of words (LOOP_NUM a) We will present them together out of (bilingual), but also in order to see how high their "accuracy."

On which intelligent voice module selection, in fact, have done a lot to understand and experiment

Initially intended use pyttsx (Python3 like to use pyttsx3), met during a lot of problems, especially for Python3, it only looked more to Soso, Chinese speech recognition problems and explore the road of pyttsx, pyttsx3 - text-to-speech x-platform , py library: text into speech (pywin32, pyttsx
after also exposed to pydub, pydub rely libav or ffmpeg, recommended reading: Kana dictation: Python audio processing library pydub, python audio processing library:. pydub
Since talking about here, we talk some more details about the audio side, for example, how to use Python to play mp3, wav, ogg format audio files
4.1 calls the default player to play

Time Import
Import os
File = R'f: /Test/musicT/Hello.mp3 '
os.system (File)
the time.sleep (10)
4.2 pygame play, but there are insufficient rate of speech distortion, pygame provides two load music method file
4.2.1 pygame.mixer.Sound, the main load ogg and wav audio files.
4.2.2 pygame.mixer.music, the main load mp3 audio files.

Time Import
Import the pygame
File = R'f: /Test/musicT/Hello.mp3 '
pygame.mixer.init ()
Track = pygame.mixer.music.load (File)
pygame.mixer.music.play ()
the time.sleep (10)
pygame.mixer.music.stop ()
4.3 mp3play playback, normal speed, but seemingly can only be used python2. *, does not support python3. *

import time
import mp3play

def playmusic(path):
clip = mp3play.load(path)
clip.play()
time.sleep(10)
clip.stop()

R'f = File: /Test/musicT/Hello.mp3 '
playmusic (File)
during programming, have encountered this problem below, to find the next task manager and end the voice is the intelligent solution for this situation process

 

Source code
, of course, you can go to Download on GitHub Latest Version, ah emmm .., thanks in advance for your star ⭐

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2018/7/27 18:01
# @Author : zhouie
# @File : main.py
# @Software: PyCharm

import speech
import time
import csv

data = [] # * .csv temporary data file for each row
Interval_Time = time interval # 4 two read word
LOOP_NUM = 8 # circular base
Think_Time = 15 # latency Review

csv_file = open('./res/test.csv', encoding='utf-8')
csv_reader_lines = csv.reader(csv_file)
# print(csv_reader_lines)

num = 0
for one_line in csv_reader_lines:
data.append(one_line)
num = num + 1

speech.say ( "Computer-related professional English translation of the English word small test program, demo version")
speech.say ( "This IS A Small routine (Compiled by Python) for the About Exercise Phrases in English at The Field, of Computer")

0 = I
the while I <NUM:
# Print (I +. 1, Data [I] [0])
# speech.say (I +. 1)
# speech.say (Data [I] [0])
# the time.sleep ( interval_time)
# speech.say (the Data [i] [0])
IF == 0 (i + 1)% LOOP_NUM:
speech.say ( "to review a few more words about what they have learned of it")
speech.say ( " the Follow Me the Just, look the Back ON at The words you have have Learned Select this item ... ")
Print (" -! ####### - * - ####### -! ")
Print (" The first ", int (i / LOOP_NUM) + 1," group words: ")
for J in Range (I - (LOOP_NUM -. 1), I +. 1):
Print (Data [J] [0], Data [J] [. 1])
speech.say (Data [J] [0])
speech.say (Data [J] [. 1])
Print ( "-! ####### - * - #### ### -! ")
speech.say (" how do you rate it right ")?
speech.say (" (So),What about your correct rate?")
time.sleep(Think_Time)
i = i + 1

speech.say("Congratulation!")

Results show: Video Demo: https://v.qq.com/x/page/o0737zviriw.html
last resource for everyone to recommend a very full skirt python learning-free non-answer: Seven bars and five Yiyi nine hundred seventy-seven under (digital homonym) conversion can be found, there is a senior programmer before learning to share experiences, study notes, there is a chance of business experience, and everyone worked up a real python zero-based information to the project, to the day python you on the latest technology, prospects, learning to leave a message of small details

Text and images in this article from the network with their own ideas, only to learn, exchange, not for any commercial purposes, belongs to original author, if any questions, please contact us for treatment.

Guess you like

Origin www.cnblogs.com/chengxuyuanaa/p/12551753.html