Download Voxforge voice files using Python

Source: Internet
Author: User

Because voice recognition requires the use of voxforge speech files, but there are too many voxforge files, manual download is definitely not acceptable. You can use the batch Download Software for download. Out of curiosity, I plan to use python to write a batch download script. Although it can be used at the end, the speed is not good, and it is a single thread. Only one file can be under one file, as a trainer, I tried to download multiple threads after a while.

Therefore, you only need to include href = "********* in the entire source code "********. the tgz section is extracted, and then "href =" "is removed, and the above primary connection is the complete connection of each file.

 

Well, let's not talk about it much. The source code is as follows, which is not standardized. Let's take a look.

Import urllibimport urllib2import osimport re OS. chdir ('d: \ voxforge speech files \ ', 'W +') # store all download connections mainpath = 'HTTP: // your gettgz (url): page = urllib. urlopen (url) html = page. read () reg = r'href =. *. tgz' tgzre = re. compile (reg) tgzlist = re. findall (tgzre, html) # Find all. tgz file for I in tgzlist: filename = I. replace ('href = ', '') filename = filename. replace ('','') print 'is being downloaded:' + filename # The system prompts downfile = I. replace ('href = ', mainpath) downfile = downfile. replace ('','') # obtain the complete connection req = urllib2.Request (downfile) for each file # download the file ur = urllib2.urlopen (req ). read () open (filename, 'wb '). write (ur) # store the downloaded file in disk D in tgz format # refiles. write (downfile + '') html = gettgz (mainpath) # refiles. close ()

 

The running effect is as follows:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.