rany2 / edge-tts

Use Microsoft Edge's online text-to-speech service from Python WITHOUT needing Microsoft Edge or Windows or an API key
https://pypi.org/project/edge-tts/
GNU General Public License v3.0
5.45k stars 556 forks source link

does it has a words limit? #26

Closed weigeloveu closed 1 year ago

weigeloveu commented 1 year ago
Traceback (most recent call last):
  File "/opt/miniconda3/bin/edge-tts", line 8, in <module>
    sys.exit(main())
  File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/util.py", line 157, in main
    asyncio.get_event_loop().run_until_complete(_main())
  File "/opt/miniconda3/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/util.py", line 150, in _main
    await _tts(args)
  File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/util.py", line 33, in _tts
    async for i in tts.run(
  File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/communicate.py", line 302, in run
    await websocket.send_str(request)
  File "/opt/miniconda3/lib/python3.9/site-packages/aiohttp/client_ws.py", line 151, in send_str
    await self._writer.send(data, binary=False, compress=compress)
  File "/opt/miniconda3/lib/python3.9/site-packages/aiohttp/http_websocket.py", line 690, in send
    await self._send_frame(message, WSMsgType.TEXT, compress)
  File "/opt/miniconda3/lib/python3.9/site-packages/aiohttp/http_websocket.py", line 601, in _send_frame
    raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport

with edge-tts --voice zh-CN-XiaoxiaoNeural -f /Users/wei/Downloads/真实的春天\,我和小姨的13年.txt --write-media 真实的春天.mp3

真实的春天,我和小姨的13年.txt

rany2 commented 1 year ago

Back when I developed it was able to generate mp3s for the GPLv3 license and other large texts but seeing it returned a connection reset error, then I suppose that people have been abusing the API too hard and that prompted Microsoft to limit the size.

Keep in mind even their official API offerings have a SSML limit of 64kbytes (for simplicity consider that SSML overhead is only 1kbytes, so you could generate for text of 63kbytes), however I was able to bypass it fairly easily when I developed this and this script should be able to handle text size greater than that limit...

rany2 commented 1 year ago

@weigeloveu It takes a long time to generate but it works fine, maybe the Great Firewall of China is doing a connection reset because it thinks it's a VPN. It took ~5 minutes to generate but it does generate eventually.

Machine translation:

生成需要很长时间,但运行良好,也许中国防火墙正在重置连接,因为它认为这是一个 VPN。 生成需要大约 5 分钟,但它最终会生成。

rany2 commented 1 year ago

Can you try with a VPN?

weigeloveu commented 1 year ago

Can you try with a VPN?

ye,i will try with vpn,but Microsoft services works in china,doent need vpn.

rany2 commented 1 year ago

@weigeloveu I know but this connection needs to remain intact for a really long time so it might look like a proxy to the firewall. In any case let me know if it works!

rany2 commented 1 year ago

There is a technique called domain fronting that tries to bypass the firewall by sending TLS SNI of an unblocked website (for example bing.com) but have the Host HTTP header be of a blocked resource.

That's how Tor's Meek bridge works, I don't know how the Chinese Firewall works but it might be an attempt to block it.

weigeloveu commented 1 year ago
(base) wei@wuyundeMacBook-Air ~ % edge-tts --voice zh-CN-XiaoxiaoNeural -f /Users/wei/Downloads/真实的春天\,我和小姨的13年.txt --write-media test.mp3      
Traceback (most recent call last):
File "/opt/miniconda3/bin/edge-tts", line 8, in <module>
sys.exit(main())
File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/util.py", line 157, in main
asyncio.get_event_loop().run_until_complete(_main())
File "/opt/miniconda3/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
return future.result()
File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/util.py", line 150, in _main
await _tts(args)
File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/util.py", line 33, in _tts
async for i in tts.run(
File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/communicate.py", line 302, in run
await websocket.send_str(request)
File "/opt/miniconda3/lib/python3.9/site-packages/aiohttp/client_ws.py", line 151, in send_str
await self._writer.send(data, binary=False, compress=compress)
File "/opt/miniconda3/lib/python3.9/site-packages/aiohttp/http_websocket.py", line 690, in send
await self._send_frame(message, WSMsgType.TEXT, compress)
File "/opt/miniconda3/lib/python3.9/site-packages/aiohttp/http_websocket.py", line 601, in _send_frame
raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
(base) wei@wuyundeMacBook-Air ~ % 

still doesn't work, even worse than don't use vpn.... the first time mp3 file is 116.1m,with vpn is 81.4m,maybe I should separate the file.maybe my vpn not stable

rany2 commented 1 year ago

This is strange, I've never had this issue and the generated mp3 was many hours long. Maybe your connection is not very stable? The issue when generating long mp3s is that any change in the connection would destroy the progress and there is no mechanism to retry where you left off.

rany2 commented 1 year ago

In any case I don't think there is a word limit, it's probably just a poor connection.

xtmu commented 9 months ago
(base) wei@wuyundeMacBook-Air ~ % edge-tts --voice zh-CN-XiaoxiaoNeural -f /Users/wei/Downloads/真实的春天\,我和小姨的13年.txt --write-media test.mp3      
Traceback (most recent call last):
  File "/opt/miniconda3/bin/edge-tts", line 8, in <module>
    sys.exit(main())
  File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/util.py", line 157, in main
    asyncio.get_event_loop().run_until_complete(_main())
  File "/opt/miniconda3/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/util.py", line 150, in _main
    await _tts(args)
  File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/util.py", line 33, in _tts
    async for i in tts.run(
  File "/opt/miniconda3/lib/python3.9/site-packages/edge_tts/communicate.py", line 302, in run
    await websocket.send_str(request)
  File "/opt/miniconda3/lib/python3.9/site-packages/aiohttp/client_ws.py", line 151, in send_str
    await self._writer.send(data, binary=False, compress=compress)
  File "/opt/miniconda3/lib/python3.9/site-packages/aiohttp/http_websocket.py", line 690, in send
    await self._send_frame(message, WSMsgType.TEXT, compress)
  File "/opt/miniconda3/lib/python3.9/site-packages/aiohttp/http_websocket.py", line 601, in _send_frame
    raise ConnectionResetError("Cannot write to closing transport")
ConnectionResetError: Cannot write to closing transport
(base) wei@wuyundeMacBook-Air ~ % 

still doesn't work, even worse than don't use vpn.... the first time mp3 file is 116.1m,with vpn is 81.4m,maybe I should separate the file.maybe my vpn not stable

If you are using ws+tls proxy it's probably your long time alive websocket connection was closed by either ISP or GFW. In my case, if proxy is on,I can only receive a max 10 minutes audio(7MB),corresponding to 2700 Chinese characters, after turning off proxy, this limit vanished. So I also believe it's a network problem rather than API problem.