Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

A tutorial on the conversion method of python speech recognition

2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report