AdvertCN - 广告中国

 找回密码
 立即注册

QQ登录

只需一步,快速开始

Adsterra China
 谷歌+Bing+TT+MSN官方代理 
⚡️按条S5代理⚡️静态⚡️独享⚡️5G皇家代理IP⚡️#1性价比⚡️Mediabuy⚡️玩家开户首选
【鲁班跨境通-自助充值转账】FB/GG/TT❤️官方免费开户Affiliate 全媒体流量资源⚡️Taboola/Outbrain /Bing⚡️一级代理
开户投流-7*24h❤️人工在线【官方】❤️搜索套利买量投流开户独立站⚡️开户投放FB BM不限额,短id账单户
E.PN 虚拟卡DuoPlus专注打造跨境电商云手机BINOM TRACKER 60% OFF!比Adplexity还好用的Spy工具
ADPLEXITY + ADVERTCN7200W全球动态不重复住宅IP代理虚拟信用卡+独立站收款全球虚拟卡, 支持U充值
Facebook 批量上广告尤里改 - FB 稳定投放免费黑五教程(持续更新、欢迎交流)FB 三不限源头 - 自助下户充值转款
各种主页、账单户、BM户(优势)⚡️个人户,bm户不限额,账单户Google、Bing官方总代  联盟流量开户FB资源,账单户,分享户,国内一手
FB企业户BM户账单户源头海外CL企业户源头PTM全球虚拟卡—进来交个朋友!PTM虚拟卡⚡️费率透明⚡️额度随心
虚拟卡 - Pay2.House【找量】BA独家Nutra单找量广告位出租8500万高质量住宅IP,助力各种需求
虚拟卡返佣1%,国内持牌机构   
查看: 20813|回复: 4

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

[复制链接]

22

主题

193

广告币

465

积分

中级会员

Rank: 3Rank: 3

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

使用道具 举报

12

主题

655

广告币

790

积分

中级会员

Rank: 3Rank: 3

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

使用道具 举报

2

主题

880

广告币

1267

积分

高级会员

Rank: 4

积分
1267

社区QQ达人

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

使用道具 举报

6

主题

303

广告币

310

积分

初级会员

Rank: 2

积分
310
发表于 2020-7-20 20:12:52 | 显示全部楼层
  1. 0 R1 o3 P, P% Z- L4 a" }0 _
  2. # -*- coding: UTF-8 -*-* i4 Q* K) z6 s7 C  }( B+ N
  3. import requests
    : l3 o0 _& R9 \! k" ]( ]
  4. import os2 \, i+ E% ]! v' b
  5. import subprocess
    3 m. D- c1 p) x
  6. import sys
    ' N* J$ A3 T+ f5 A
  7. from tqdm import tqdm
    3 L4 W8 u# H. H
  8. import time,random
    0 `0 d6 ^+ z  F0 B2 h8 K9 U
  9. from HTMLParser import HTMLParser
    5 n2 n: l$ N  x; w" {$ e/ P, j
  10. import sys    {5 Y/ }  O/ f
  11. reload(sys)  9 F+ J: c8 i  a9 a
  12. sys.setdefaultencoding('utf8')
    1 T# U1 X/ Q/ \- `6 P1 R2 a
  13. 4 Z% h. L4 \! }* h6 |  s: y) }
  14. class WebRequest(object):6 D+ g. p4 Q6 n7 i4 n5 A( s
  15.     def __init__(self, *args, **kwargs):
    8 {1 r# F: `* w" e
  16.         pass
    1 W/ D% }( M+ t/ e2 w6 ^: o) ^

  17. # w) m2 Y  B  D3 E
  18.     @property
    ) M% U& x6 E0 K
  19.     def user_agent(self):
    1 g' m1 |9 l& x' H& c* C
  20.         """9 q+ \8 E; s& _/ g5 ^' H
  21.         return an User-Agent at random$ Q9 T9 x! G# Q1 W0 l& [
  22.         :return:$ {# A+ u3 e6 q. ~
  23.         """
    5 m1 a0 d+ [, n) r+ [" S' N: c& P
  24.         ua_list = [
    ) I1 D6 U( v! }' M: B5 z9 d* `
  25.             'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1599.101',
    ' g- V, J. r' V8 j) p3 ]0 A
  26.             'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.122',
    . V4 X9 d* S3 V$ s' B
  27.             'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.71',
    : R) D* ?: K- P2 \, `
  28.             'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95',
    9 F& J. w6 G2 p; H
  29.             'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.71',4 ?5 f7 {5 p: @: W* k
  30.             'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; QQDownload 732; .NET4.0C; .NET4.0E)',
      s) o. l! Q( \9 P
  31.             'Mozilla/5.0 (Windows NT 5.1; U; en; rv:1.8.1) Gecko/20061208 Firefox/2.0.0 Opera 9.50',
    8 A2 Q$ T. ?  e# i" D7 o7 x
  32.             'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:34.0) Gecko/20100101 Firefox/34.0',. O% ?, ?3 ^: ^4 Q
  33.             ]
    - q9 z: h- n# C, T
  34.         return random.choice(ua_list)
      w. u0 n+ i0 H1 {! B- z. s6 ?3 w
  35. # N+ I6 `& n/ E0 C7 `
  36.     @property6 T5 C5 C# |- N3 Z) j4 {/ m
  37.     def header(self):
    , p( q' A$ M& D& o6 q: L( {$ e! [
  38.         """
    1 Y8 ]: j7 |' m9 A6 M/ p
  39.         basic header0 ?* ]# |  o# }" F% Q! O  A  D
  40.         :return:0 v& Z! V7 A$ O8 _
  41.         """
    * \& Z$ |: w7 r5 h" C2 x) k
  42.         return {'User-Agent': self.user_agent,
    - s+ F0 ]* V8 D
  43.                 'Accept': '*/*',# Z: P( f9 `3 m; l; u; a% g
  44.                 'Connection': 'keep-alive',8 X6 M' D( o* b0 g  ~- Z7 e
  45.                 'Accept-Language': 'zh-CN,zh;q=0.8'}% }" C6 q( X# Z' z5 V2 z

  46. ' a; o) E4 N) P$ W
  47.     def get(self, url, header=None, retry_time=5, timeout=30,2 ^  P  ^) w$ b7 z1 X# G9 J
  48.             retry_flag=list(), retry_interval=5, *args, **kwargs):, _  O% y9 J1 p: b( ~5 z' g1 o
  49.         """! K% B2 }7 L/ R. x- O5 S
  50.         get method% a1 C: U3 h# z6 c, k4 [" D
  51.         :param url: target url- q# B* v8 C6 ]$ P  C* i2 l; e' E
  52.         :param header: headers
    7 I7 ?7 a2 o4 @1 w( O+ e& N
  53.         :param retry_time: retry time when network error) h' f* h7 x0 J2 U/ y
  54.         :param timeout: network timeout
    0 q, r/ }( K" ]5 m4 L  K" M
  55.         :param retry_flag: if retry_flag in content. do retry& [9 V' c  y5 q
  56.         :param retry_interval: retry interval(second)5 z; Q% P; A# R$ Y- n
  57.         :param args:
    & c6 |6 z; N: P1 I  W4 \
  58.         :param kwargs:$ F0 L8 g. S; N' N" O( K
  59.         :return:; x) A$ V0 j3 r1 l
  60.         """5 k: x$ V! `( @% r' y
  61.         headers = self.header
    * U, K8 |; c: V# `; z1 K+ _7 e" j# @
  62.         if header and isinstance(header, dict):
    8 P# a- v$ e( T) D% M, p$ a
  63.             headers.update(header): [7 W& y& X* {
  64.         while True:
      _' N4 f1 H+ S
  65.             try:
    6 {8 G  R; Y9 J+ m
  66.                 html = requests.get(url, headers=headers, timeout=timeout, stream=True)9 w  [# n0 j* T4 G5 ~
  67.                 print 'content size: %d' % len(html.content)5 i1 ]$ b: j, i. b
  68.                 if any(f in html.content for f in retry_flag):3 h- M& J3 J- v& S/ d
  69.                     raise Exception/ o9 O( x0 Z% R" k; K0 N: C
  70.                 if not html.content:! g- k  x7 u8 A# y, B+ r& W# \
  71.                     print 'content is Null,retry...~' + url
    * M) K& Z) n7 X
  72.                     raise Exception$ H9 k9 g* I. Y) s0 g  p: n
  73.                 return html; G: E8 k/ [1 v! m  A; n  e
  74.             except Exception as e:
    ! c9 |4 d* U3 ?+ T
  75.                 print(e)/ W+ y* ]0 o1 B/ ~+ X$ |/ ?6 O
  76. # V, }3 l/ L/ _% \
  77. + {$ {% T  h3 o$ E, T& {" G
  78. def DownloadAudio(url, path, refer=None):
    ; J& _  ]( n- n! U9 ~! q
  79.         with open(path, 'wb') as handle:: ^9 r# B& Z; H0 ?# w* j8 |8 U
  80.                 if refer:
    5 x$ x, _, K$ y9 f3 a
  81.                                 hdr = {
    0 [9 q3 o0 U1 F9 t
  82.                                    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',
    9 ~3 u/ e9 _  u/ g
  83.                                    'Referer': refer}
    + j8 u  @1 Q; p' J+ G  _! ~* d
  84.                 else:
    ( I1 g2 j. u; V( o: r
  85.                                 hdr = {! o% b9 v8 Q3 O1 S1 y
  86.                                    'User-Agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11',, Q  _& N! H. _; h/ Y: c( _! p
  87.                                    'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',3 L& z3 v, x/ F
  88.                                    'Accept-Charset': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3',8 c# g6 B% [9 i# t/ u
  89.                                    'Accept-Encoding': 'none',
    9 S9 v; |/ E; Z% e& C
  90.                                    'Accept-Language': 'en-US,en;q=0.8',
    0 v' b8 A' A; b; W' O3 ^8 r
  91.                                    'Connection': 'keep-alive'}
    " ]0 Q; w+ U+ y
  92.                 wr = WebRequest()
    % T& y8 _& x( F( `9 h
  93.                 #print hdr
    0 G8 V& s0 ?6 c
  94.                 response = wr.get(url,header=hdr)! R9 J3 w* u  N
  95.                 #html = requests.get('https://www.example.com', proxies={"http": "http://{}".format(p!r!o!x!y)})
    ( P/ x% y. r3 P
  96.                 #response = requests.get(url, stream=True, headers={'User-agent': 'Mozilla/5.0'})  V: q4 H3 Z, _
  97.                 #print url6 \- r; D& ?4 c' I! Z
  98.                 for block in tqdm(response.iter_content(),ascii=True, desc='ImageDownload'):
    + \, \4 C1 T0 v
  99.                         if not block:$ Q  Q4 J7 K4 h( H
  100.                                 break
    ! I  {( E3 |2 }) a
  101.                         handle.write(block)4 Q' A: V4 v! l) L3 s

  102. $ ]* u6 J: Z- |6 w8 t
  103. def translate(to_translate, to_langage="auto", langage="auto"):
    ) Z7 C. p; D% f, f5 a; w
  104. '''Return the translation using google translate0 j! K9 ?0 e7 J, N( t$ B5 y8 T) @
  105. you must shortcut the langage you define (French = fr, English = en, Spanish = es, etc...)/ E( z& [" ?) @- \4 T$ b
  106. if you don't define anything it will detect it or use english by default; J4 W8 _5 W3 _0 x) \8 W
  107. Example:$ _7 ^$ f+ K7 X6 Y  K$ {( d: {
  108. print(translate("salut tu vas bien?", "en"))/ v5 K$ h$ z* X$ d
  109. hello you alright?''', X# p4 x( D0 e
  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)"}
    # f. {# l% W4 B$ x' D3 p; o( t
  111. before_trans = 'class="t0">'/ d9 @# a; P, l9 m8 J* ~, k! _1 L
  112. link = "http://translate.google.com/m?ie=UTF-8&hl=%s&sl=%s&q=%s" % (to_langage, langage, to_translate.replace(" ", "+"))( g: p5 l. |# e+ n
  113. request = requests.get(link, headers=agents)% [9 R4 c/ `& B* t; z" l. n, D
  114. page = request.content" h+ R- G9 E2 u
  115. #print page- M1 H1 q- z% ]: y
  116. result = page[page.find(before_trans)+len(before_trans):]
    ; ~/ ?8 c0 ]( W! j& b
  117. result = result.split("<")[0]
    $ o' o5 Y. S3 Y7 E9 g/ G
  118. return result9 L  B9 J( a% ~% C; D
  119. 8 u$ P4 [  I7 h: W$ b
  120. tsxt_sen = []
    8 D6 W; s2 l0 V2 w$ Q- {
  121. from nltk.tokenize import sent_tokenize
    , e8 w0 k# }8 R6 h0 G
  122. def sentence_split(sentence): # 编写分句函数
    : n4 B+ H5 [$ x& Z2 J5 U8 f2 H
  123.     text_sen = []
    7 _: k# e# ]' k$ L2 j9 g
  124.     for s in sentence.split(','):) V. C/ q/ p. q8 F' |& C$ s" {6 I
  125.        # if '?' in s:
    6 ^3 D2 s1 i1 e
  126.        #     tsxt_sen.extend(s.split('?'))+ |4 r! a& @! a7 N( v
  127.        # elif ',' in s:
    & F, I- ~. z$ B2 Z9 M0 w
  128.        #     tsxt_sen.extend(s.split(','))& {2 |5 D# c/ I5 O8 E) Z
  129.        # else:1 C! L. v0 f6 c3 W
  130.        text_sen.append(s)# _5 }5 B# C7 s( [+ e% G
  131.     return tsxt_sen
    / i& r$ B2 {( E7 m% i* s8 J
  132. 6 K( M. z+ v. w
  133. 7 I/ W: s. k/ ^, t
  134. str = '''
    % S% u1 f+ o6 [
  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, h+ S( W, H/ O  f

  136. 2 x6 S2 w& D, s7 O) e0 }
  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.
    2 S: ?- Z; L) o
  138. - ?; H: p# y  p* X4 t8 |$ L6 a5 K
  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.# l& R9 l$ `9 f% Z' L  y. K

  140. 5 `' k$ t$ _: @$ p; c9 D4 `
  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. 0 m" d% \* q! f
  142. 1 s" S% J5 U# q6 Z6 U% \0 A1 E
  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.( {' p5 r) d/ I5 y3 \/ P3 l
  144. 6 w( \4 c3 `) S+ M* r% v
  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.
    * B  ^3 [+ g7 \* P) w, [5 k0 n

  146. ; T( o) |& _7 I6 R5 \" [" z7 y+ F8 [
  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.' z6 N& g! e; D* T
  148. '''2 @3 M, K% h2 \0 `# ?/ |

  149. ) v# r8 [/ m: d3 C! _$ `3 B! K

  150. 9 r4 E) a* r3 R
  151. text = ''.join(str).strip().lstrip().rstrip().replace('\n',' ')
    - G$ G5 T$ U+ A" B" n9 I$ N
  152. with open('~/text.txt', 'wb') as handle:* w3 D4 ]% X6 q& o9 ~0 `
  153.     handle.write(text)
    7 c$ r$ c, l5 r& \, R/ G
  154. + j, ]  E2 a+ J; }, A2 M) m
  155. str = str.replace('”','"')
    . V( J1 a2 S: c/ y
  156. str = str.replace('“','"')2 c6 I' C+ e3 h& Z. U
  157. + V' }, t$ ?3 ]
  158. 8 D/ \4 m. d: V+ x; h# j3 {* X
  159. def splitStr(str):
    0 h% n$ \' T* p  p4 Q+ C$ K6 N7 W" ^
  160.     arr = str.split(' ')
    * h% N, W( q5 C8 t4 _
  161.     sz = len(arr)
      W1 ?, P$ d; y( m9 u8 I
  162.     return [' '.join(arr[0:sz/2]),' '.join(arr[(sz/2):])]& a, Y2 W/ `' |5 q, @+ @
  163.     6 n6 C/ M  y, i" c6 B' x# ^' l

  164. 2 Q. [; `# H3 P
  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.')
    " h" Q" c6 |+ u0 Q1 M

  166. % t# _/ @$ |. P' d
  167. keyArr = []
    % i- b0 i6 [( @3 n) b% B( Z7 j  x% d5 b
  168. sent_tokenize_list = sent_tokenize(str)/ r$ e% ?- f7 ~$ V
  169. for s in sent_tokenize_list:8 u! D# t( S3 ~, n
  170.     sz = len(' '.join(s.split()))
    * z( Y6 Y1 e( N! A
  171.     if sz <= 190:% ^2 N+ `3 D8 O
  172.         keyArr.append(' '.join(s.split()))! u' J- D  Q; L; R+ x& \3 j; s
  173.         #print '[ '+' '.join(s.split())+' ]'
    1 ]7 U8 r+ ~4 |  l  {
  174.     else:% C6 c5 A9 U1 ~7 |- n0 W4 q6 d
  175.         for ses in s.split(','):- K  K* {7 A) V7 J5 K
  176.             if len(ses) > 190:
    4 h+ n# \& R0 d) R
  177.                 keyArr.extend(splitStr(ses))
    % Z2 }9 b0 Z+ `  ~9 o6 L  Y3 I
  178.             else:, p) R! F; G3 g/ p( V7 w
  179.                 keyArr.append(' '.join(ses.split()))7 ]  Z5 C0 H8 p/ b& ^; @

  180. 6 u; I3 Z; j0 h" y/ c  O/ c4 i
  181. : z" t! w" Y) D* {0 q
  182. API_URL = "http://translate.google.com/translate_tts?ie=UTF-8&tl=en-us"
    & S7 n- T& ?% P' e" i9 j
  183. #key = HTMLParser.unescape.__func__(HTMLParser, translate(str,'en'))
    # y0 v1 k, X% |! S* x/ u3 E
  184. #keyArr = sentence_split(str)
    % m5 v; l& U* ]; @

  185. * G1 c! y( B+ W

  186. 0 l/ a0 E8 ]4 }2 n/ J! M
  187. #print([text[i:i+n] for i in xrange(0, len(text), n)])
    5 h4 J% s0 Q( s  ~+ }
  188. os.system('rm ~/tmp/audio/*.mp3')
    3 Z9 s4 K0 ]& D& C, N- {& ^
  189. namei = 0
    0 ?8 f' o+ @) \: R0 }8 |$ k- M1 W
  190. for i in keyArr:/ L- j- C* k1 y4 H
  191.     juzi = ' '.join(i.split())0 I& p; H+ `5 q+ p5 f4 I. a: K
  192.     sz = len(juzi)
    $ c6 @  X3 U9 h2 y  Z. [; O
  193.     link = API_URL+"&q="+juzi+"&client=tw-ob"+ I$ o$ z" Q: x3 D4 B% {- F1 |
  194.     print link0 O& J, [$ N5 I3 ?/ e
  195.     path = "~/tmp/audio/%d.mp3" % namei" p6 h* E/ g6 M( k
  196.         #print path
    6 s& |; W; \0 @
  197.     DownloadAudio(link,path)
    $ w9 ~* `1 ~8 Y" q  Q' m: @
  198.     os.system('file '+path)
    $ ^& v+ d9 I# x% j0 m4 v
  199.     time.sleep(1)
    ! R( J. N: _1 u3 g( B1 h. j
  200.     namei = namei + 1
    * m" l! C1 Y2 N- M: Y' [' i
复制代码
回复 支持 反对

使用道具 举报

93

主题

1855

广告币

3406

积分

金牌会员

Rank: 6Rank: 6

积分
3406
发表于 2020-7-20 21:07:36 | 显示全部楼层
https://azure.microsoft.com/en-u ... ces/text-to-speech/
# o- _% R/ P8 h2 _, b0 @* \# Z8 G8 L( r
微软的,应该不错吧!~
已有1人评分           广告币           理由
     河小马         +10,000,000       太帅了
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2025-7-6 07:14 , Processed in 0.060896 second(s), 15 queries , Gzip On, MemCache On.

Copyright © 2001-2023, AdvertCN

Proudly Operating in Hong Kong.

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