ToryPan / ChatGPT_WeChat

未认证微信公众号接入chatgpt,新增语音聊天(英语对话),基于Flask,实现个人微信公众号【无认证】接入ChatGPT
153 stars 42 forks source link

能添加使用代理吗? #3

Closed IIE-Safety closed 1 year ago

ToryPan commented 1 year ago

好的,我后续补充加上去,如果现在着急使用的话,你可以先在gptManage.py文件里面对send_request和send_request_voice两个函数进行更改。

IIE-Safety commented 1 year ago

嗯呢嗯呢,我使用了proxychains4进行暂时使用。作者大大,想问另一个问题,运行的时候发现azure api调用失败了。我使用以下python脚本进行调用测试,也调用失败,报出如下问题。想问一下是不是申请azure语音服务时,选择的区域会受影响呢?

import azure.cognitiveservices.speech as speechsdk
from azure.cognitiveservices.speech import SpeechSynthesizer
from azure.cognitiveservices.speech.audio import AudioOutputConfig
speech_key, service_region = "API KEY", "eastus"
speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)
#设置合成的音频为中文
speech_config.speech_synthesis_language = "zh-CN"  
# 设置保存音频的文件
audio_config = AudioOutputConfig(filename="test.mp3")
#在控制台输入想要合成的话
print("在控制台输入想要合成的话: ")
text = input()
#创建synthesizer对象,
synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
# 调用speak_text_async 将文本合成为音频
synthesizer.speak_text_async(text)
Traceback (most recent call last):
  File "/opt/text2voice.py", line 14, in <module>
    synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
  File "/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/speech.py", line 2149, in __init__
    _call_hr_fn(fn=_sdk_lib.synthesizer_create_speech_synthesizer_from_config, *[
  File "/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/interop.py", line 62, in _call_hr_fn
    _raise_if_failed(hr)
  File "/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/interop.py", line 55, in _raise_if_failed
    __try_get_error(_spx_handle(hr))
  File "/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/interop.py", line 50, in __try_get_error
    raise RuntimeError(message)
RuntimeError: Exception with error code: 
[CALL STACK BEGIN]

/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1cdf71) [0x7fc6311cdf71]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1ea0dd) [0x7fc6311ea0dd]
/lib/x86_64-linux-gnu/libc.so.6(+0x99f68) [0x7fc632167f68]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1eb29a) [0x7fc6311eb29a]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1a30d7) [0x7fc6311a30d7]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1a2983) [0x7fc6311a2983]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1cf821) [0x7fc6311cf821]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1bb4ac) [0x7fc6311bb4ac]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1b6bc4) [0x7fc6311b6bc4]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0xe7885) [0x7fc6310e7885]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1cf821) [0x7fc6311cf821]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1aeb33) [0x7fc6311aeb33]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(+0x1f7d3c) [0x7fc6311f7d3c]
/usr/local/lib/python3.10/dist-packages/azure/cognitiveservices/speech/libMicrosoft.CognitiveServices.Speech.core.so(synthesizer_create_speech_synthesizer_from_config+0xf3) [0x7fc6310cfcae]
/lib/x86_64-linux-gnu/libffi.so.8(+0x7e2e) [0x7fc631a24e2e]
/lib/x86_64-linux-gnu/libffi.so.8(+0x4493) [0x7fc631a21493]
/usr/lib/python3.10/lib-dynload/_ctypes.cpython-310-x86_64-linux-gnu.so(+0xa451) [0x7fc631a3b451]
[CALL STACK END]

Runtime error: Failed to initialize platform (azure-c-shared). Error: 2153
ToryPan commented 1 year ago

我刚刚用这段代码试了一下,没得问题,得保证speech_key, service_region这两个参数和azure里面的配置一致,你看看是不是这两个设置有问题呢? image

import azure.cognitiveservices.speech as speechsdk from azure.cognitiveservices.speech import SpeechSynthesizer from azure.cognitiveservices.speech.audio import AudioOutputConfig speech_key, service_region = "API KEY", "eastus" speech_config = speechsdk.SpeechConfig(subscription=speech_key, region=service_region)

设置合成的音频为中文

speech_config.speech_synthesis_language = "zh-CN"

设置保存音频的文件

audio_config = AudioOutputConfig(filename="test.mp3")

在控制台输入想要合成的话

print("在控制台输入想要合成的话: ") text = input()

创建synthesizer对象,

synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)

调用speak_text_async 将文本合成为音频

synthesizer.speak_text_async(text)

dhf2587154870 commented 1 year ago

想问下大佬我按照步骤修改了config.json里面的api 密匙等等 80端口也开启了 为什么启动程序后 在网页输入服务器IP显示未找到 在服务器上找不到请求的 URL。如果您手动输入 URL,请检查您的拼写并重试。

dhf2587154870 commented 1 year ago

![Uploading WeChat截图_20230422170539.png…]()

ToryPan commented 1 year ago

想问下大佬我按照步骤修改了config.json里面的api 密匙等等 80端口也开启了 为什么启动程序后 在网页输入服务器IP显示未找到 在服务器上找不到请求的 URL。如果您手动输入 URL,请检查您的拼写并重试。

代码里面是把默认的路由关闭了,你可以把下面的代码取消注释,并确保ip_detection设置为false,然后输入IP地址试试。在微信公众号后台填写的地址应该为:IP/wechat/

# @app.route("/")
# def hello():
#     return "Hello test!"
dhf2587154870 commented 1 year ago

想问下大佬我按步骤修改了config.json里面的api密码等80端口也开启了 为什么启动程序后在网页输入服务器IP显示的未显示L果您手动输入网址,请检查您的拼写并重试。

代码里面是把默认的路由关闭了,你可以把下面的代码取消消消注解,并确保设置为false,然后输入IP地址试一下。在微信公/我们聊天/

# @app.route("/")
# def hello():
#     return "Hello test!"

请问你刚给的代码是加在config.yml里面么。就把ip_detection设置成false就行了么?

ToryPan commented 1 year ago

想问下大佬我按步骤修改了config.json里面的api密码等80端口也开启了 为什么启动程序后在网页输入服务器IP显示的未显示L果您手动输入网址,请检查您的拼写并重试。

代码里面是把默认的路由关闭了,你可以把下面的代码取消消消注解,并确保设置为false,然后输入IP地址试一下。在微信公/我们聊天/

# @app.route("/")
# def hello():
#     return "Hello test!"

请问你刚给的代码是加在config.yml里面么。就把ip_detection设置成false就行了么?

“@app.route("/")”这个代码在:myflask.py这个文件里面,默认是被注释掉了,所以启动后不能直接通过ip地址访问,如果你要直接用ip地址访问进行测试,需要把这个路由的注释取消掉。然后公众号的接口是放在@app.route("/wechat/")这个路由里面的,所以公众号后台需要设置url地址为:你的ip地址/wechat/。然后ip_detection的作用是检测请求的ip是否是微信服务器发送的,在config.yml里面设置,如果这个选项设置为true,非微信服务器ip对/wechat/的请求会被404。

dhf2587154870 commented 1 year ago

想问下大佬我按步骤修改了config.json里面的api密码等80端口也开启了 为什么启动程序后在网页输入服务器IP显示的未显示L果您手动输入网址,请检查您的拼写并重试。

代码里面是把默认的路由关闭了,你可以把下面的代码取消消消注解,并确保设置为false,然后输入IP地址试一下。在微信公/我们聊天/

# @app.route("/")
# def hello():
#     return "Hello test!"

请问你刚给的代码是加在config.yml里面么。就把ip_detection设置成false就行了么?

“@app.route("/")”这个代码在:myflask.py这个文件里面,默认是被注释掉了,所以启动后不能直接通过ip地址访问,如果你要直接用ip地址访问进行测试,需要把这个路由的注释取消掉。然后公众号的接口是放在@app.route("/wechat/")这个路由里面的,所以公众号后台需要设置url地址为:你的ip地址/wechat/。然后ip_detection的作用是检测请求的ip是否是微信服务器发送的,在config.yml里面设置,如果这个选项设置为true,非微信服务器ip对/wechat/的请求会被404。

谢谢 是用vim myflask.py 然后修改成@app.route("/") def hello(): return "Hello test!" 这样 并且把ip_detection设置成false 这样就可以通过微信公众号部署机器人成功么

ToryPan commented 1 year ago

想问下大佬我按步骤修改了config.json里面的api密码等80端口也开启了 为什么启动程序后在网页输入服务器IP显示的未显示L果您手动输入网址,请检查您的拼写并重试。

代码里面是把默认的路由关闭了,你可以把下面的代码取消消消注解,并确保设置为false,然后输入IP地址试一下。在微信公/我们聊天/

# @app.route("/")
# def hello():
#     return "Hello test!"

请问你刚给的代码是加在config.yml里面么。就把ip_detection设置成false就行了么?

“@app.route("/")”这个代码在:myflask.py这个文件里面,默认是被注释掉了,所以启动后不能直接通过ip地址访问,如果你要直接用ip地址访问进行测试,需要把这个路由的注释取消掉。然后公众号的接口是放在@app.route("/wechat/")这个路由里面的,所以公众号后台需要设置url地址为:你的ip地址/wechat/。然后ip_detection的作用是检测请求的ip是否是微信服务器发送的,在config.yml里面设置,如果这个选项设置为true,非微信服务器ip对/wechat/的请求会被404。

谢谢 是用vim myflask.py 然后修改成@app.route("/") def hello(): return "Hello test!" 这样 并且把ip_detection设置成false 这样就可以通过微信公众号部署机器人成功么

设置正确的话应该能成功的

dhf2587154870 commented 1 year ago

想问下大佬我按步骤修改了config.json里面的api密码等80端口也开启了 为什么启动程序后在网页输入服务器IP显示的未显示L果您手动输入网址,请检查您的拼写并重试。

代码里面是把默认的路由关闭了,你可以把下面的代码取消消消注解,并确保设置为false,然后输入IP地址试一下。在微信公/我们聊天/

# @app.route("/")
# def hello():
#     return "Hello test!"

请问你刚给的代码是加在config.yml里面么。就把ip_detection设置成false就行了么?

“@app.route("/")”这个代码在:myflask.py这个文件里面,默认是被注释掉了,所以启动后不能直接通过ip地址访问,如果你要直接用ip地址访问进行测试,需要把这个路由的注释取消掉。然后公众号的接口是放在@app.route("/wechat/")这个路由里面的,所以公众号后台需要设置url地址为:你的ip地址/wechat/。然后ip_detection的作用是检测请求的ip是否是微信服务器发送的,在config.yml里面设置,如果这个选项设置为true,非微信服务器ip对/wechat/的请求会被404。

谢谢 是用vim myflask.py 然后修改成@app.route("/") def hello(): return "Hello test!" 这样 并且把ip_detection设置成false 这样就可以通过微信公众号部署机器人成功么

设置正确的话应该能成功的

WeChat截图_20230422170539 大佬 我按照你的指示把myflask.py里面的注释取消了 但是运行flask run --host=0.0.0.0 --port=80就报错 33 555

ToryPan commented 1 year ago

三行前面都多了个空格,我把这个问题关了,你要是还有其他问题,重新开一个吧,这个问题是别人开的。