AdvertCN - 广告中国

 找回密码
 立即注册

QQ登录

只需一步,快速开始

Binom
 谷歌+Bing+TT+MSN官方代理 
⚡️按条S5代理⚡️静态⚡️独享⚡️5G⚡️最干净<Wifi住宅+5G移动>IP代理指纹浏览器,就用AdsPower
Mediabuy⚡️玩家开户首选【鲁班跨境通-自助充值转账】FB/GG/TT❤️官方免费开户Affiliate 全媒体流量资源⚡️
Taboola/Outbrain /Bing⚡️一级代理开户投流-7*24h❤️人工在线【官方】❤️搜索套利广告开户独立站⚡️开户投放
DuoPlus专注打造跨境电商云手机E.PN 虚拟卡BINOM TRACKER 60% OFF!比Adplexity还好用的Spy工具
MediaGo+Taboola+Ob开户百度国际MediaGo⚡️让产品狂奔全球百度国际,高点击转化,快速放量百度国际MediaGo,独家原生流量
ADPLEXITY + ADVERTCN7200W全球动态不重复住宅IP代理虚拟信用卡+独立站收款全球虚拟卡, 支持U充值
Facebook 批量上广告尤里改 - FB 稳定投放免费黑五教程(持续更新、欢迎交流)FB 三不限源头 - 自助下户充值转款
各种主页、账单户、BM户(优势)⚡️个人户,bm户不限额,账单户一手BM分享户不限额9Proxy ⚡️ $0.04/IP, 无限带宽
FB二三解0.1元一个虚拟卡|PTM星际卡FB专用虚拟卡Google、Bing官方总代  联盟流量开户
FB账号资源/稳定靠谱/运行5年啦FB开户代投/三不限/白名单fb耐用号0.01一个fb账号官方合作商
广告位出租   
查看: 20534|回复: 4

[求助] 求一个英文转化语音的网站

[复制链接]

22

主题

193

广告币

465

积分

中级会员

Rank: 3Rank: 3

积分
465
发表于 2020-7-20 15:06:35 | 显示全部楼层 |阅读模式
回复

使用道具 举报

12

主题

651

广告币

786

积分

中级会员

Rank: 3Rank: 3

积分
786
发表于 2020-7-20 16:20:57 | 显示全部楼层
google一下,好多。免费的,不限次...
.
寻----兼职机会★懂英语★熟外贸★写文案★会视频剪辑
V❤:丫iωu⑤①⑧⑧
.
.
回复 支持 反对

使用道具 举报

2

主题

877

广告币

1264

积分

高级会员

Rank: 4

积分
1264

社区QQ达人

发表于 2020-7-20 16:56:14 | 显示全部楼层
naturalreaders
回复 支持 反对

使用道具 举报

6

主题

303

广告币

310

积分

初级会员

Rank: 2

积分
310
发表于 2020-7-20 20:12:52 | 显示全部楼层

  1. 2 f/ D9 [6 D$ y
  2. # -*- coding: UTF-8 -*-9 h, F6 e9 w" P5 o1 n
  3. import requests
    9 i7 U- b4 c1 [
  4. import os
    ; Q! V# O& F  }/ a- w6 U
  5. import subprocess- H' B1 T  ?6 A& ^' B0 b7 n( e5 v
  6. import sys
    7 l. q" b: z3 |
  7. from tqdm import tqdm4 T8 o  J$ y+ J# Z5 _
  8. import time,random7 J1 y8 Y: h' g5 Y; y
  9. from HTMLParser import HTMLParser
    $ U. a; S* ~7 m. j
  10. import sys  
    * L! j0 e* j- e7 u# p
  11. reload(sys)  
    $ v  v3 W# @2 ]) C2 q$ I
  12. sys.setdefaultencoding('utf8')
    0 y" ^: f* I. Y0 G

  13. ) M6 T0 b" L1 x5 S3 Y# E' S* V
  14. class WebRequest(object):# a2 c. w9 i/ r9 E" G: A1 \5 ~
  15.     def __init__(self, *args, **kwargs):
    $ B5 Z# U" p0 [$ D6 S
  16.         pass
    - e% N) @3 \6 @! `1 X. \
  17. ( o* F  c: i6 V: T+ D3 g* s
  18.     @property
    % ^9 Q3 U/ f2 R4 J, C$ ^- V# v
  19.     def user_agent(self):
    8 @* Q" {8 D4 Y, w$ X* G
  20.         """
    . |5 @1 b+ p3 R# ]; x9 a* u: ]* h. L: {
  21.         return an User-Agent at random
    ) @, J" ?: v# ^$ m0 z. d9 `
  22.         :return:
    ! k" {1 W0 \9 _( D$ M4 A
  23.         """7 k9 G8 P2 j$ R4 o4 J7 O
  24.         ua_list = [
    ) Z) ?, l5 [3 R8 f2 D4 d3 p
  25.             'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101',
    ) S" H- C" H6 ]& X+ q0 G
  26.             'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122',9 n- L" j+ Q& J: D* ]' V% }, v4 A
  27.             'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71',- O# K8 G4 r) s: ?# n
  28.             'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95',
    ; N1 P: X+ V) P4 W# w5 U
  29.             'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71',5 Z; P& K' f$ @) k% H6 h
  30.             'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)'," d7 O3 j( G9 F4 J+ \3 y
  31.             'Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.50',
    4 Q* |. A  r/ _
  32.             'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0',
      k! }- Q$ h1 h6 Z  G0 I. ?  p
  33.             ]* u0 {3 h/ ]  A4 Z
  34.         return random.choice(ua_list)
    7 s0 s3 s& ?" G$ A7 K$ S

  35. ' N3 J/ Y$ q" K$ M5 r
  36.     @property
    & i( G2 @$ a0 }1 @$ }
  37.     def header(self):
    " ^$ D7 ?4 ~  c4 i* n
  38.         """
    & F/ \) O" ?$ O5 n
  39.         basic header2 k# \# q7 ^8 }6 }
  40.         :return:$ u1 ~3 J% ^/ n; p
  41.         """# j% J  K; P& q5 y. ]- P9 Q1 }& d
  42.         return {'User-Agent': self.user_agent," N& w+ i6 S( i- e* s! r
  43.                 'Accept': '*/*',
      ^' m9 b" ]! U2 _4 G* t
  44.                 'Connection': 'keep-alive',3 K* R" }% i9 k& y+ ^3 D" F
  45.                 'Accept-Language': 'zh-CN,zh;q=0.8'}
    : c5 s7 ]5 Y; `- ?* C

  46. 6 e' Q5 e1 r& K: U1 T3 M) o
  47.     def get(self, url, header=None, retry_time=5, timeout=30,- ~5 E9 g& R8 q3 u+ d$ L5 t
  48.             retry_flag=list(), retry_interval=5, *args, **kwargs):) F- d+ c" M- k' ^& A1 O9 w
  49.         """7 x1 R1 z0 a$ A9 M: H2 ~
  50.         get method
    3 R8 B4 M; L; n# {  v  E
  51.         :param url: target url
    7 f1 Z" y. e) k( H4 ^
  52.         :param header: headers
    8 d: W9 h3 `' l5 x! f+ z/ \
  53.         :param retry_time: retry time when network error% n, b' r8 n  s8 |
  54.         :param timeout: network timeout
    $ A3 r( [0 O. l3 ]
  55.         :param retry_flag: if retry_flag in content. do retry
    4 i- ^. a' d. Z0 N1 Z+ u) M6 w1 d
  56.         :param retry_interval: retry interval(second): s) G( y4 z& n- ^
  57.         :param args:
    6 F: f! [9 P3 N6 f: t) j! C
  58.         :param kwargs:, h$ `5 N' t- F  g: e  V
  59.         :return:& T# z( K: f8 W) [, k) Q
  60.         """
    6 Z, e) H/ [7 Q4 h5 g6 _. J
  61.         headers = self.header0 v, v9 k. B/ Z/ Y; U0 {3 l. `% [4 ~$ D
  62.         if header and isinstance(header, dict):
    $ d% i" H& f+ Z/ ~) F5 ]. Y1 O
  63.             headers.update(header)
    4 h- P* E! H% l7 z4 |# G, ~
  64.         while True:
    / E9 Z, ]6 I9 |8 l* t3 c
  65.             try:& \# f! Q: Z+ }. o1 i
  66.                 html = requests.get(url, headers=headers, timeout=timeout, stream=True)6 S% ]* V, _' E6 W) r
  67.                 print 'content size: %d' % len(html.content)3 h4 K1 ~) c+ g3 l( B
  68.                 if any(f in html.content for f in retry_flag):) Q0 Z) k% E7 Y! o1 N) E7 E3 B, ]
  69.                     raise Exception/ n, O# y6 \  O5 h) g
  70.                 if not html.content:8 `$ e" D" t' \  O/ I6 P* O
  71.                     print 'content is Null,retry...~' + url6 V/ k  M9 a3 X6 i6 b3 w% c; w8 F
  72.                     raise Exception
    $ _0 T% F( i7 J% G& s
  73.                 return html; c, Y) y) H$ x2 w6 y8 [
  74.             except Exception as e:& G  T4 F* ~6 b
  75.                 print(e); I) i- G# h1 v( O$ @+ C" h
  76. 0 f5 X6 y% C' Q! [  M
  77. ; `9 Q/ d0 @" ?9 J7 s
  78. def DownloadAudio(url, path, refer=None):( e) M. \; N) r( i! m3 e
  79.         with open(path, 'wb') as handle:
    ' E  X* i  H* M4 i2 U* A& _2 S
  80.                 if refer:
    ' n4 |5 W1 M+ d/ K' c: Y; {4 @
  81.                                 hdr = {
    8 b' w7 K8 G; M# ?
  82.                                    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',# f6 {! N& T( _5 f% ?. r
  83.                                    'Referer': refer}
    . p1 [( x: i2 N: p
  84.                 else:' t! R! n) q- ^8 r2 M
  85.                                 hdr = {( R8 Y: u0 I  d& C' B% S3 U$ h5 N: z2 ~
  86.                                    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
    8 r- P! ?& w- \) P' e( m4 y
  87.                                    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
      H" J/ |3 j4 d8 J
  88.                                    'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',
    + o( |/ v  J# d0 a4 m
  89.                                    'Accept-Encoding': 'none',
    1 a3 J4 u; Q% G4 U  h! z: ^
  90.                                    'Accept-Language': 'en-US,en;q=0.8',, l/ X, N8 w& y. Q, T3 Z. ]1 B2 O1 k
  91.                                    'Connection': 'keep-alive'}
    , }$ N: |) P3 G% k
  92.                 wr = WebRequest()! |. T- y- f) S. j5 V6 q0 B
  93.                 #print hdr
    4 o, L' ~- P- w% d) R3 L
  94.                 response = wr.get(url,header=hdr)
    8 V9 c6 k$ g) v0 y# F
  95.                 #html = requests.get('https://www.example.com', proxies={"http": "http://{}".format(p!r!o!x!y)})
    ! q. t! V" V% S# _# H
  96.                 #response = requests.get(url, stream=True, headers={'User-agent': 'Mozilla/5.0'})3 f' v6 M2 X7 m( f$ s
  97.                 #print url
    1 W! h& S; w( ?5 i; S2 L: _
  98.                 for block in tqdm(response.iter_content(),ascii=True, desc='ImageDownload'):1 }$ {) O4 \; L) |# i9 t3 I1 p: g
  99.                         if not block:2 l5 h# G9 J; H( }
  100.                                 break% ]9 j  ~$ q  }
  101.                         handle.write(block); I/ e7 V5 L7 H3 b. d" `% a
  102. " q* L5 }6 |0 K2 b
  103. def translate(to_translate, to_langage="auto", langage="auto"):
    " d9 V$ ]5 W7 a, M7 {7 p# P0 a
  104. '''Return the translation using google translate
    9 w( p' T6 K5 p! U! ~9 j
  105. you must shortcut the langage you define (French = fr, English = en, Spanish = es, etc...). u" C# @- F3 D
  106. if you don't define anything it will detect it or use english by default4 E5 N. w& N/ N+ c/ W
  107. Example:  z. d+ T9 U2 u5 ]
  108. print(translate("salut tu vas bien?", "en"))6 j; V. _5 n. S
  109. hello you alright?'''3 D$ y3 }, G7 o8 |9 p3 n! t
  110. agents = {'User-Agent':"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.30)"}
    % E/ Y4 G. c. w( [. o* G
  111. before_trans = 'class="t0">'
    5 p% Y, S4 K' p; [
  112. link = "http://translate.google.com/m?ie=UTF-8&hl=%s&sl=%s&q=%s" % (to_langage, langage, to_translate.replace(" ", "+"))
    . M& z* `+ |$ j' R
  113. request = requests.get(link, headers=agents)
    + F: _% I) ~- b/ V  [/ Z/ Z+ P! ^
  114. page = request.content  H& T5 A( Q6 ?( @1 {& ~+ l
  115. #print page# K" y: j' `2 K) f) K7 q
  116. result = page[page.find(before_trans)+len(before_trans):]- P) ^, I7 o& k. A7 A. H$ z
  117. result = result.split("<")[0]1 A- D. s, J; J1 A6 F
  118. return result3 Y' }( A+ B/ e  r9 g
  119. 2 y3 f( Y. I8 g: O) {  p
  120. tsxt_sen = []
    2 T2 a; k% C0 ]0 m2 z1 N. |  m/ \1 ]
  121. from nltk.tokenize import sent_tokenize. u) j5 A, z9 G+ _- A% x
  122. def sentence_split(sentence): # 编写分句函数- t' f, V5 h+ B" r1 A
  123.     text_sen = []; k1 }: s2 e% j7 s, _  O7 z
  124.     for s in sentence.split(','):; n8 f8 N2 U6 a! _1 {! o
  125.        # if '?' in s:, U; ^( L* b3 u* [2 ]- D
  126.        #     tsxt_sen.extend(s.split('?'))
    7 z# i( ^* b9 x1 u
  127.        # elif ',' in s:% [% u1 v# n7 m+ @
  128.        #     tsxt_sen.extend(s.split(','))
    / {4 A, x' N' X% j
  129.        # else:2 J! l$ v6 F, v: O' @# l9 x" [
  130.        text_sen.append(s)4 A, z  b8 A0 t/ t$ t8 ^  \" m9 E: O
  131.     return tsxt_sen" }' H) }0 b# Q6 b+ o. K7 S
  132. ) L) c( \1 Y4 i; m5 s6 `
  133. 4 `, Z0 E( Z+ z) W  d; G  ], l2 m
  134. str = '''! o& A! L$ y+ J& e4 J  B- S% }2 Q
  135. It has not quite been greeted with the enthusiasm of the bottles of Scotch in the novel Whisky Galore, but the arrival of a cargo of pineapples on the shores of northern Scotland has sent scavengers rushing to the beach.& W: d# F& ?" g7 k) \) |

  136. / @% s0 B6 V! A, R3 x0 N
  137. The fruit, which has appeared on Shetland and on beaches across the Western Isles, is thought to have come from several containers lost overboard in the Atlantic last October by cargo ship MV Lombok Strait.
    " ~. i- R8 b# S9 _" T

  138. ! ]0 {/ A' S3 _4 [8 H! A) ?3 i
  139. Shetland islanders have now shared photos of their fruitful haul, in a story that echoes the plot of Whisky Galore, the 1947 novel by Sir Compton Mackenzie, later made and remade for the big screen.% ^' i' E! @. F- c- {- v
  140. ( K' f  G8 m5 w: R
  141. The story tells of how the locals find their island awash with whisky after a ship loaded with liquor is wrecked off a fictional Scottish island.
    5 P, i* b" f$ V+ {: y8 J

  142. & U/ l1 ^1 E! j, N0 h6 i8 P
  143. The plot was based on the real-life salvage operations carried out by locals when the SS Politician, carrying 280,000 bottles of malt whisky, ran aground on Eriskay in 1943.
    - T: K% Y4 ], d" A: M: r
  144. " y* l# S2 t& G6 W  t
  145. The arrival of the pineapples will be far less lucrative for beachcombers, and not as profitable, either, as the grounding of the cargo ship MSC Napoli off Branscombe beach in Devon in 2007.6 N5 q5 A' w9 Y9 P2 w2 F

  146. - }" N, u1 S2 x; B
  147. Then scavengers ignored police advice and arrived in their droves to explore shipping containers, which contained motorbikes, pet food, wine barrels and anti-wrinkle cream.' O2 J; p3 a6 e( u
  148. '''* P& a/ d/ D% u& `" V9 `% y
  149. ; \2 I6 J. U; w, S
  150. , t$ o7 f% J7 j! W; X: b
  151. text = ''.join(str).strip().lstrip().rstrip().replace('\n',' ')
    . }1 R! H3 V. ]: K
  152. with open('~/text.txt', 'wb') as handle:
    7 |: a4 S! Y3 a! H, [+ `3 C, y
  153.     handle.write(text)$ A- p& Z, T9 c, Y' }0 s

  154. 4 w  [/ K6 [1 m; g( Q# i
  155. str = str.replace('”','"')
    4 e: _( B$ G- }5 U. ~
  156. str = str.replace('“','"')
    , J: P8 c. ]+ D: N) O0 b9 Y+ o

  157. / Z/ |: p5 J4 k' r

  158. % U' @$ [" q. x( x9 t' P
  159. def splitStr(str):# r) u- e! o* G8 M$ h, r0 Z
  160.     arr = str.split(' '): [$ f, h' W! E+ X8 e/ z
  161.     sz = len(arr)
    8 `  g  g. g; u8 [: g6 S
  162.     return [' '.join(arr[0:sz/2]),' '.join(arr[(sz/2):])]8 [" V6 x. {: }$ L. o8 O
  163.    
    2 y( [3 b. l6 N$ p
  164. 8 n; L; I4 K+ U7 ]* g1 e! x
  165. #print splitStr('with wording from North Korea about getting rid of its nuclear weapons and a guarantee from the United States that it would not interfere with the North’s regime or demand redress for human rights abuses.')
    # b! O% l' L) c# Q+ ~

  166. 4 U8 ^" Y; h/ P5 o' k- X0 g$ x
  167. keyArr = []" F! U5 j% {. g& i  O
  168. sent_tokenize_list = sent_tokenize(str)
    & M" @! d% C8 t8 \5 s
  169. for s in sent_tokenize_list:. F0 `- [1 X+ x% _4 A
  170.     sz = len(' '.join(s.split()))
    . R( h: b" E9 M( \6 T
  171.     if sz <= 190:! a- Z$ P5 q/ K2 z; e
  172.         keyArr.append(' '.join(s.split()))
    6 B  ?# u, b2 z! U% B9 i" o* h
  173.         #print '[ '+' '.join(s.split())+' ]'
    7 D, T0 n7 Q: z0 ^; \8 ~. g+ d
  174.     else:# m5 `: U; l# M# [" E2 i
  175.         for ses in s.split(','):
    $ g* h7 ?0 R9 B4 e* s
  176.             if len(ses) > 190:; R1 |6 }3 ?, i0 p+ q; Q
  177.                 keyArr.extend(splitStr(ses))
    3 M; B/ q' F' o& i( J; S/ U- `9 }
  178.             else:: f2 Q' M5 N- \! N+ C7 W* H
  179.                 keyArr.append(' '.join(ses.split()))
    ( v, v3 T) q% o8 m3 L, m
  180. 2 }; e" l. V3 m3 C- i

  181. 6 t1 o# S& F! e6 B
  182. API_URL = "http://translate.google.com/translate_tts?ie=UTF-8&tl=en-us"8 |- \; \& V( P' ^; ]
  183. #key = HTMLParser.unescape.__func__(HTMLParser, translate(str,'en'))
    . Y3 {8 G+ H$ ~2 ?+ y# g0 L" {: v
  184. #keyArr = sentence_split(str)
    ' a( D8 Y/ T  l1 S0 C5 W3 P

  185. $ ^8 {. A$ k7 A" q1 i

  186. ( P5 x4 j: V$ q- \1 o
  187. #print([text[i:i+n] for i in xrange(0, len(text), n)])
    3 t) L) Q2 X* m, @- n9 b: ?
  188. os.system('rm ~/tmp/audio/*.mp3')
    8 r. x) s4 b  ?, |  c2 k2 ?
  189. namei = 0
    9 y$ U; e3 r& D  |2 K: ^) O0 J
  190. for i in keyArr:: o0 t: m' w1 @3 x- z
  191.     juzi = ' '.join(i.split())5 ?$ S9 F& F$ X; b+ p& j3 I
  192.     sz = len(juzi)
    ' @' d/ {- J% Q& B$ K
  193.     link = API_URL+"&q="+juzi+"&client=tw-ob"
    " ]: B. D* n$ n' K
  194.     print link; d3 b6 f, I, E/ S' Y
  195.     path = "~/tmp/audio/%d.mp3" % namei: N8 ?9 G, l& h3 V. q
  196.         #print path+ ~) B- x* i  n& t- b1 ]+ G' Y
  197.     DownloadAudio(link,path)
    # m4 X9 V0 ?, ]' o) w1 ^# t
  198.     os.system('file '+path)
    * d8 g! `+ q' ?' D! ]! l
  199.     time.sleep(1)# m$ b# X6 |/ e8 ?1 Z
  200.     namei = namei + 1" s" S. c3 B& u. o* c" Z6 |: ~0 i6 }
复制代码
回复 支持 反对

使用道具 举报

84

主题

1572

广告币

3086

积分

高级会员

Rank: 4

积分
3086
发表于 2020-7-20 21:07:36 | 显示全部楼层
https://azure.microsoft.com/en-u ... ces/text-to-speech/! w, L6 D# j* L# d; }' R2 f' w- S

; w, U5 p' |: a; n0 `+ g6 s8 e微软的,应该不错吧!~
已有1人评分           广告币           理由
     河小马         +10,000,000       太帅了
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关于我们|联系我们|DMCA|广告服务|小黑屋|手机版|Archiver|Github|网站地图|AdvertCN

GMT+8, 2024-11-24 14:47 , Processed in 0.046783 second(s), 16 queries , Gzip On, MemCache On.

Copyright © 2001-2023, AdvertCN

Proudly Operating in Hong Kong.

快速回复 返回顶部 返回列表