current position:Home>Inventory a voice conversion library

Inventory a voice conversion library

2022-05-15 07:21:10Python advanced

Hello everyone , I'm Pippi .

One 、 Preface

A few days ago Python There is a member of Xingyao communication group called 【 Duolong 】 My fans asked Python Library voice conversion problem , Take it out here and share it with you , Let's study together .

 Inventory a voice conversion library

This is his element code :

from gtts import gTTSimport  ostts = gTTS(text=" Speak Chinese ha, I think I can read it well ", lang="zh-tw")tts.save("hello1.mp3")

Two 、 To solve the process

【dcpeng】 answer

This voice library needs to be installed , Installation method ( Additive source ):pip install -i https://pypi.tuna.tsinghua.edu.cn/simple gTTS.

 Inventory a voice conversion library

Otherwise, the following error will be prompted :

 Inventory a voice conversion library

After installation , Run code , There will still be mistakes , Because there is a problem with the original code , There is a parameter wrong , According to the tips on the official website ,lang=zh-TW It's just .

from gtts import gTTSimport ostts = gTTS(text=" Speak Chinese ha, I think I can read it well ", lang="zh-TW")tts.save("hello1.mp3")

 Inventory a voice conversion library

But unfortunately , Or an error , As shown in the figure below :

 Inventory a voice conversion library

The reason is this gtts Need to connect to Google Server for , But if you don't surf the Internet scientifically , In fact, you can't visit .

If you can't connect to the Internet , either vpn, Do how? ?

Don't panic , below 【 Mr. Yu Liang 】 The boss gave the solution .

【 Mr. Yu Liang 】 answer

This is 【 Mr. Yu Liang 】 The code given by the boss , Just set the domain name , As shown below :

from gtts import gTTStts = gTTS(text=" Speak Chinese ha, I think I can read it well ", lang="zh-TW", tld='com.cn')tts.save("hello1.mp3")

In this way, it can be generated smoothly , No need for scientific Internet access can also be converted in actual combat .

 Inventory a voice conversion library

Yes, of course ,tld='cn' It's the same , This is calling translate.google.cn, The example above is to call translate.google.com.cn, The added parameter is tld='com.cn'.

 Inventory a voice conversion library

The following figure is the official document :

 Inventory a voice conversion library

3、 ... and 、 summary

Hello everyone , I'm Pippi . This article mainly shares a Python Deal with the use of voice conversion library , Specific analysis and code demonstration are given to solve this problem , There are two ways , Help the fans solve the problem smoothly .

More about gTTs Problems with library usage , You can go to the official website :Module (gtts) — gTTS documentation https://gtts.readthedocs.io/en/latest/module.html#languages-gtts-lang see .

 Inventory a voice conversion library

Finally thanks 【 Duolong 】 put questions to , thank 【dcpeng】 and 【 Mr. Yu Liang 】 The specific analysis and code demonstration given by the boss , thank 【 Chen Ma Chen Cheng 】、【 Luna 】、【Lasu】 And others participate in learning and communication .

friends , Practice it quickly ! If in the process of learning , Any problems encountered , Welcome to add my friend , I'll pull you in Python The learning exchange group discusses learning together .

copyright notice
author[Python advanced],Please bring the original link to reprint, thank you.
https://en.chowdera.com/2022/131/202205102149185665.html

Random recommended