Get the App
SLTechnology News&Howtos  ›  Development  › 

A tutorial on the conversion method of python speech recognition

Shulou Source: shulou.com Published: 2022-06-03 03:57:20 10月03日 Update

This article mainly introduces "the conversion method course of python speech recognition". In the daily operation, I believe that many people have doubts about the conversion method tutorial of python speech recognition. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "conversion method tutorial of python speech recognition". Next, please follow the editor to study!

With pyttsx's python package, you can convert text to voice.

Installation command

Pip install pyttsx3-I https://pypi.tuna.tsinghua.edu.cn/simple

Run a simple voice saying "Hello, everyone".

Import pyttsx3 as pyttsxengine = pyttsx.init () # initialize engine.say ('Hello') engine.runAndWait ()

Another text-to-speech method.

From win32com.client import Dispatchspeaker = Dispatch ('SAPI.SpVoice') # create Dispatch object speaker.Speak (' Hello everyone') # call Speak method del speaker # release

This method may report an error.

ImportError: DLL load failed while importing win32api: the specified module was not found.

The website downloads the "pywin32" installer appropriate to the "Python" version of your installation.

Use SpeechLib to complete text conversion language from comtypes.client import CreateObjectfrom comtypes.gen import SpeechLib engine = CreateObject ('SAPI.SpVoice') # call method stream = CreateObject (' SAPI.SpFileStream') # stream output to target object infile = '1.txt' # text to read outfile =' demo_audio.wav' # output to voice file stream.open (outfile,SpeechLib.SSFMCreateForWrite) engine.AudioOutputStream = stream# read text content f = open (infile,'r' Encoding='utf-8') theText = f.read () f.close () engine.speak (theText) stream.close () use PocketSphinx to convert voice to text

Install two toolkits first

Pip install PocketSphinxpip install SpeechRecognition

Then download the Chinese recognition of cmusphinx-zh-cn-5.2.tar and put it in the directory of anaconda's python virtual environment.

Under the path Lib\ site-packages\ speech_recognition\ pocketsphinx-data

Rename the unzipped file to zh-CN

# convert speech to text using PocketSphinximport speech_recognition as sraudio_file = 'demo_audio.wav'r = sr.Recognizer () with sr.AudioFile (audio_file) as source: # Open the voice file and read audio = r.record (source) try: print (' text content:', r.recognize_sphinx (audio)) # default recognition to English print ('text content:', r.recognize_sphinx (audio) Language='zh-CN')) # specify Chinese except Exception as e: print (e) to this The study of "python speech recognition conversion method tutorial" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!

Tags: Voice method text tutorials learning content files objects more website Chinese help output utility next two commands tools toolkits articles Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Technology Xiaomi Redmi Shulou Information Docker