继续上一篇,基于wsl2的docker-desktop创建fast-whisper无法正常运行,错误日志如下:
2023-07-06 17:10:29 Traceback (most recent call last):
2023-07-06 17:10:29 File "/usr/local/lib/python3.8/dist-packages/gradio/routes.py", line 394, in run_predict
2023-07-06 17:10:29 output = await app.get_blocks().process_api(
2023-07-06 17:10:29 File "/usr/local/lib/python3.8/dist-packages/gradio/blocks.py", line 1075, in process_api
2023-07-06 17:10:29 result = await self.call_function(
2023-07-06 17:10:29 File "/usr/local/lib/python3.8/dist-packages/gradio/blocks.py", line 884, in call_function
2023-07-06 17:10:29 prediction = await anyio.to_thread.run_sync(
2023-07-06 17:10:29 File "/usr/local/lib/python3.8/dist-packages/anyio/to_thread.py", line 31, in run_sync
2023-07-06 17:10:29 return await get_asynclib().run_sync_in_worker_thread(
2023-07-06 17:10:29 File "/usr/local/lib/python3.8/dist-packages/anyio/_backends/_asyncio.py", line 937, in run_sync_in_worker_thread
2023-07-06 17:10:29 return await future
2023-07-06 17:10:29 File "/usr/local/lib/python3.8/dist-packages/anyio/_backends/_asyncio.py", line 867, in run
2023-07-06 17:10:29 result = context.run(func, *args)
2023-07-06 17:10:29 File "app.py", line 103, in transcribe_webui_simple_progress
2023-07-06 17:10:29 return self.transcribe_webui(modelName, languageName, urlData, multipleFiles, microphoneData, task, vadOptions,
2023-07-06 17:10:29 File "app.py", line 197, in transcribe_webui
2023-07-06 17:10:29 result = self.transcribe_file(model, source.source_path, selectedLanguage, task, vadOptions, scaled_progress_listener, **decodeOptions)
2023-07-06 17:10:29 File "app.py", line 280, in transcribe_file
2023-07-06 17:10:29 process_gaps = self._create_silero_config(NonSpeechStrategy.CREATE_SEGMENT, vadOptions)
2023-07-06 17:10:29 File "app.py", line 368, in _create_silero_config
2023-07-06 17:10:29 self.vad_model = VadSileroTranscription()
2023-07-06 17:10:29 File "/opt/whisper-webui/src/vad.py", line 437, in __init__
2023-07-06 17:10:29 self._initialize_model()
2023-07-06 17:10:29 File "/opt/whisper-webui/src/vad.py", line 445, in _initialize_model
2023-07-06 17:10:29 self.model, self.get_speech_timestamps = self._create_model()
2023-07-06 17:10:29 File "/opt/whisper-webui/src/vad.py", line 449, in _create_model
2023-07-06 17:10:29 model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad', model='silero_vad')
2023-07-06 17:10:29 File "/usr/local/lib/python3.8/dist-packages/torch/hub.py", line 537, in load
2023-07-06 17:10:29 repo_or_dir = _get_cache_or_reload(repo_or_dir, force_reload, trust_repo, "load",
2023-07-06 17:10:29 File "/usr/local/lib/python3.8/dist-packages/torch/hub.py", line 180, in _get_cache_or_reload
2023-07-06 17:10:29 repo_owner, repo_name, ref = _parse_repo_info(github)
2023-07-06 17:10:29 File "/usr/local/lib/python3.8/dist-packages/torch/hub.py", line 133, in _parse_repo_info
2023-07-06 17:10:29 with urlopen(f"https://github.com/{repo_owner}/{repo_name}/tree/main/"):
2023-07-06 17:10:29 File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
2023-07-06 17:10:29 return opener.open(url, data, timeout)
2023-07-06 17:10:29 File "/usr/lib/python3.8/urllib/request.py", line 525, in open
2023-07-06 17:10:29 response = self._open(req, data)
2023-07-06 17:10:29 File "/usr/lib/python3.8/urllib/request.py", line 542, in _open
2023-07-06 17:10:29 result = self._call_chain(self.handle_open, protocol, protocol +
2023-07-06 17:10:29 File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
2023-07-06 17:10:29 result = func(*args)
2023-07-06 17:10:29 File "/usr/lib/python3.8/urllib/request.py", line 1397, in https_open
2023-07-06 17:10:29 return self.do_open(http.client.HTTPSConnection, req,
2023-07-06 17:10:29 File "/usr/lib/python3.8/urllib/request.py", line 1357, in do_open
2023-07-06 17:10:29 raise URLError(err)
2023-07-06 17:10:29 urllib.error.URLError: <urlopen error [Errno 111] Connection refused>
2023-07-06 17:10:29 Traceback (most recent call last):
2023-07-06 17:10:29 File "/usr/lib/python3.8/urllib/request.py", line 1354, in do_open
2023-07-06 17:10:29 h.request(req.get_method(), req.selector, req.data, headers,
2023-07-06 17:10:29 File "/usr/lib/python3.8/http/client.py", line 1256, in request
2023-07-06 17:10:29 self._send_request(method, url, body, headers, encode_chunked)
2023-07-06 17:10:29 File "/usr/lib/python3.8/http/client.py", line 1302, in _send_request
2023-07-06 17:10:29 self.endheaders(body, encode_chunked=encode_chunked)
2023-07-06 17:10:29 File "/usr/lib/python3.8/http/client.py", line 1251, in endheaders
2023-07-06 17:10:29 self._send_output(message_body, encode_chunked=encode_chunked)
2023-07-06 17:10:29 File "/usr/lib/python3.8/http/client.py", line 1011, in _send_output
2023-07-06 17:10:29 self.send(msg)
2023-07-06 17:10:29 File "/usr/lib/python3.8/http/client.py", line 951, in send
2023-07-06 17:10:29 self.connect()
2023-07-06 17:10:29 File "/usr/lib/python3.8/http/client.py", line 1418, in connect
2023-07-06 17:10:29 super().connect()
2023-07-06 17:10:29 File "/usr/lib/python3.8/http/client.py", line 922, in connect
2023-07-06 17:10:29 self.sock = self._create_connection(
2023-07-06 17:10:29 File "/usr/lib/python3.8/socket.py", line 808, in create_connection
2023-07-06 17:10:29 raise err
2023-07-06 17:10:29 File "/usr/lib/python3.8/socket.py", line 796, in create_connection
2023-07-06 17:10:29 sock.connect(sa)
2023-07-06 17:10:29 ConnectionRefusedError: [Errno 111] Connection refused
很明显是github无法访问,我首先想到的是docker无法走系统的代理,wsl也不行,通过在docker和wsl中运行curl https://www.google.com可以测试。(fast-whisper镜像不像whiper那样把东西都放进去了,每次运行时还要加载东西,造成这个问题。也就是说whisper官方镜像可以全脱网运行,fast-whisper则不行。)
那么怎么让没有开通局域网共享功能的梯子来分享网络呢?通过一阵子检索,终于发现了二级代理和链式代理这个概念,最终确定用gost试一试。
1 在windows上找到当前的代理
打开网络连接的“网络和Internet设置”,打开设置中的“代理”。如果你安装了某个代理程序,则这里应该能够看到设置的端口。比如地址:http://localhost,端口:15236。
注意,这里的localhost很重要,因为收费的代理不希望你局域网共享,所以限制只能通过localhost访问。如果没有这个限制,那就简单了,直接把代理设置为主机的IP和端口就行了。
2 安装gost作为二级代理
由于我的梯子是在win10上的,所以需要让gost也在win上运行,所以安装了win版的go,然后安装/build这个gost,目录下就有gost.ext了,运行:
.\gost -L=:15230 -F=localhost:15236
二级代理就启动了,最直接的是在另外一台电脑上设置这个IP加端口15230试试,发现代理成功。试了一下,必须是localhost,不能是127.0.0.1。
为了方便,我把这个设置了自动启动,在gost.exe所在目录增加一个名为gost.ps1的文件,内容如下:
.\gost.exe -L=:16236 -F=localhost:15236
同样在这个目录再增加一个gost.bat,内容如下:
Powershell.exe -executionpolicy remotesigned -File ./gost.ps1
然后在gost.bat上右键创建一个快捷方式,把这个快捷方式放到开机启动目录C:\Users\PS\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
可以通过徽标键+R打开shell:startup
3 在wsl中配置代理的启用
然后可以借鉴WSL2配置代理 – Leaos – 博客园 (cnblogs.com)来设置wsl2中的代理。
还有个问题,DNS也要先加上8.8.8.8,不然域名解析被污染了,依然无法访问github。
一个更方便的方法,在wsl的用户主目录增加一个文件proxy.sh,内容如下:
#!/bin/sh
# hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
hostip='192.168.0.200'
wslip=$(hostname -I | awk '{print $1}')
port=16236
PROXY_HTTP="http://${hostip}:${port}"
PROXY_SOCKS5="socks5://${hostip}:${port}"
set_proxy(){
export http_proxy="${PROXY_HTTP}"
export HTTP_PROXY="${PROXY_HTTP}"
export https_proxy="${PROXY_HTTP}"
export HTTPS_proxy="${PROXY_HTTP}"
export ALL_PROXY="${PROXY_SOCKS5}"
export all_proxy="${PROXY_SOCKS5}"
git config --global http.https://github.com.proxy ${PROXY_HTTP}
git config --global https.https://github.com.proxy ${PROXY_HTTP}
echo "Proxy has been opened."
test_setting
}
unset_proxy(){
unset http_proxy
unset HTTP_PROXY
unset https_proxy
unset HTTPS_PROXY
unset ALL_PROXY
unset all_proxy
git config --global --unset http.https://github.com.proxy
git config --global --unset https.https://github.com.proxy
echo "Proxy has been closed."
}
test_setting(){
echo "Host IP:" ${hostip}
echo "WSL IP:" ${wslip}
echo "Current https_proxy:" $https_proxy
echo "Current all_proxy:" $all_proxy
echo "Try to connect to Google..."
resp=$(curl -I -s --connect-timeout 5 -m 5 -w "%{http_code}" -o /dev/null www.google.com)
if [ ${resp} = 200 ]; then
echo "Proxy setup succeeded!"
else
echo "Proxy setup failed!"
fi
}
if [ "$1" = "set" ]
then
set_proxy
elif [ "$1" = "unset" ]
then
unset_proxy
elif [ "$1" = "test" ]
then
test_setting
else
echo "Unsupported arguments."
fi
注意,其中的hostip我没有用其他文档给的方法,因为不确定一定对,我改成了本机的固定IP。
然后在.bashrc文件结尾增加
alias proxy="source ~/proxy.sh set"
alias unproxy="source ~/proxy.sh unset"
这样,在source ~/.bashrc之后,就可以直接在shell中输入proxy来启用,或者输入unproxy来停用了。
再进一步,想要在打开shell时自动配置,可以新建一个autoproxy.sh
#!/bin/sh
# hostip=$(cat /etc/resolv.conf | grep nameserver | awk '{ print $2 }')
hostip='192.168.0.200'
wslip=$(hostname -I | awk '{print $1}')
port=16236
PROXY_HTTP="http://${hostip}:${port}"
PROXY_SOCKS5="socks5://${hostip}:${port}"
export http_proxy="${PROXY_HTTP}"
export HTTP_PROXY="${PROXY_HTTP}"
export https_proxy="${PROXY_HTTP}"
export HTTPS_proxy="${PROXY_HTTP}"
export ALL_PROXY="${PROXY_SOCKS5}"
export all_proxy="${PROXY_SOCKS5}"
git config --global http.https://github.com.proxy ${PROXY_HTTP}
git config --global https.https://github.com.proxy ${PROXY_HTTP}
echo "Proxy has been opened."
然后在.bashrc中增加
if [ -f "/home/yourusername/autoproxy.sh" ]; then
. "/home/yourusername/autoproxy.sh"
fi