Regarding errors related to websockets, asyncio, pyvts, customtkinter

I would like to create a program that embeds the vtubestudio and voicevox api in a GUI button created with customtkinter (from now on I will abbreviate it as ctk), so that vtubestudio and voicevox will work when the button is pressed. However, when I prototype it and get it working, I get a “web socket error”. I think this probably indicates that the server side of the api is not keeping up with the processing. How can I resolve this error? Below is the program

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>from voicevox_adapter import VoicevoxAdapter
from play_sound import PlaySound
import pyvts
import asyncio
import customtkinter as ctk
input_str = "こんにちは"
va = VoicevoxAdapter()
ps = PlaySound("スピーカー")
data,rate = va.get_voice(input_str)
app = ctk.CTk()
app.geometry("400x240")
plugin_info = {
"plugin_name": "trigger hotkey",
"developer": "OverHome",
"authentication_token_path": "./pyvts_token.txt"
}
async def voice():
ps.play_sound(data,rate)
async def main():
myvts = pyvts.vts(plugin_info=plugin_info)
await myvts.connect()
await myvts.request_authenticate_token() # get token
await myvts.request_authenticate() # use token
response_data = await myvts.request(myvts.vts_request.requestHotKeyList())
hotkey_list = []
for hotkey in response_data['data']['availableHotkeys']:
hotkey_list.append(hotkey['name'])
send_hotkey_request = myvts.vts_request.requestTriggerHotKey(hotkey_list[0])
return myvts,send_hotkey_request
myvts, send_hotkey_list = asyncio.run(main())
async def doing():
await asyncio.sleep(5)
await myvts.request(send_hotkey_list)
await voice()
def doing_def():
asyncio.run(doing())
button = ctk.CTkButton(app,
text="実行",
command=doing_def,
width=200,height=120)
button.grid(column=2,row=1)
app.mainloop()
</code>
<code>from voicevox_adapter import VoicevoxAdapter from play_sound import PlaySound import pyvts import asyncio import customtkinter as ctk input_str = "こんにちは" va = VoicevoxAdapter() ps = PlaySound("スピーカー") data,rate = va.get_voice(input_str) app = ctk.CTk() app.geometry("400x240") plugin_info = { "plugin_name": "trigger hotkey", "developer": "OverHome", "authentication_token_path": "./pyvts_token.txt" } async def voice(): ps.play_sound(data,rate) async def main(): myvts = pyvts.vts(plugin_info=plugin_info) await myvts.connect() await myvts.request_authenticate_token() # get token await myvts.request_authenticate() # use token response_data = await myvts.request(myvts.vts_request.requestHotKeyList()) hotkey_list = [] for hotkey in response_data['data']['availableHotkeys']: hotkey_list.append(hotkey['name']) send_hotkey_request = myvts.vts_request.requestTriggerHotKey(hotkey_list[0]) return myvts,send_hotkey_request myvts, send_hotkey_list = asyncio.run(main()) async def doing(): await asyncio.sleep(5) await myvts.request(send_hotkey_list) await voice() def doing_def(): asyncio.run(doing()) button = ctk.CTkButton(app, text="実行", command=doing_def, width=200,height=120) button.grid(column=2,row=1) app.mainloop() </code>
from voicevox_adapter import VoicevoxAdapter
from play_sound import PlaySound
import pyvts
import asyncio
import customtkinter as ctk

input_str = "こんにちは"
va = VoicevoxAdapter()
ps = PlaySound("スピーカー")
data,rate = va.get_voice(input_str)
app = ctk.CTk()
app.geometry("400x240")

plugin_info = {
    "plugin_name": "trigger hotkey",
    "developer": "OverHome",
    "authentication_token_path": "./pyvts_token.txt"
}

async def voice():
    ps.play_sound(data,rate)

async def main():
    myvts = pyvts.vts(plugin_info=plugin_info)
    await myvts.connect()
    await myvts.request_authenticate_token()  # get token
    await myvts.request_authenticate()  # use token
    response_data = await myvts.request(myvts.vts_request.requestHotKeyList())
    hotkey_list = []
    for hotkey in response_data['data']['availableHotkeys']:
        hotkey_list.append(hotkey['name'])
    send_hotkey_request = myvts.vts_request.requestTriggerHotKey(hotkey_list[0])  
    return myvts,send_hotkey_request

myvts, send_hotkey_list = asyncio.run(main())

async def doing():
    await asyncio.sleep(5)
    await myvts.request(send_hotkey_list)
    await voice()

def doing_def():
    asyncio.run(doing())

button = ctk.CTkButton(app,
                       text="実行",
                       command=doing_def,
                       width=200,height=120)
button.grid(column=2,row=1)

app.mainloop()

I would like to create a program that would allow vtubestudio and voicevox to work when the button is pressed.

However, when I prototype and get it working, I get a “web socket error”. This probably indicates that the server side of the api is not keeping up with the processing.

Here is the full text of the error

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>Exception in Tkinter callback
Traceback (most recent call last):
File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 963, in transfer_data
message = await self.read_message()
File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 1033, in read_message
frame = await self.read_data_frame(max_size=self.max_size)
File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 1108, in read_data_frame
frame = await self.read_frame(max_size)
File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 1165, in read_frame
frame = await Frame.read(
File "C:Pythonlibsite-packageswebsocketslegacyframing.py", line 68, in read
data = await reader(2)
File "C:Pythonlibasynciostreams.py", line 723, in readexactly
await self._wait_for_data('readexactly')
File "C:Pythonlibasynciostreams.py", line 517, in _wait_for_data
await self._waiter
asyncio.exceptions.CancelledError
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "C:Pythonlibtkinter__init__.py", line 1892, in __call__
return self.func(*args)
File "C:Pythonlibsite-packagescustomtkinterwindowswidgetsctk_button.py", line 554, in _clicked
self._command()
File "c:UsersHOME anyoneDocumentsAIVtuberProjectvoicevoxasync&ctk.py", line 42, in doing_def
asyncio.run(doing())
File "C:Pythonlibasynciorunners.py", line 44, in run
return loop.run_until_complete(main)
File "C:Pythonlibasynciobase_events.py", line 616, in run_until_complete
return future.result()
File "c:UsersHOME anyoneDocumentsAIVtuberProjectvoicevoxasync&ctk.py", line 38, in doing
await myvts.request(send_hotkey_list)
File "C:Pythonlibsite-packagespyvtsvts.py", line 112, in request
await self.websocket.send(json.dumps(request_msg))
File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 635, in send
await self.ensure_open()
File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 939, in ensure_open
raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: no close frame received or sent
</code>
<code>Exception in Tkinter callback Traceback (most recent call last): File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 963, in transfer_data message = await self.read_message() File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 1033, in read_message frame = await self.read_data_frame(max_size=self.max_size) File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 1108, in read_data_frame frame = await self.read_frame(max_size) File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 1165, in read_frame frame = await Frame.read( File "C:Pythonlibsite-packageswebsocketslegacyframing.py", line 68, in read data = await reader(2) File "C:Pythonlibasynciostreams.py", line 723, in readexactly await self._wait_for_data('readexactly') File "C:Pythonlibasynciostreams.py", line 517, in _wait_for_data await self._waiter asyncio.exceptions.CancelledError The above exception was the direct cause of the following exception: Traceback (most recent call last): File "C:Pythonlibtkinter__init__.py", line 1892, in __call__ return self.func(*args) File "C:Pythonlibsite-packagescustomtkinterwindowswidgetsctk_button.py", line 554, in _clicked self._command() File "c:UsersHOME anyoneDocumentsAIVtuberProjectvoicevoxasync&ctk.py", line 42, in doing_def asyncio.run(doing()) File "C:Pythonlibasynciorunners.py", line 44, in run return loop.run_until_complete(main) File "C:Pythonlibasynciobase_events.py", line 616, in run_until_complete return future.result() File "c:UsersHOME anyoneDocumentsAIVtuberProjectvoicevoxasync&ctk.py", line 38, in doing await myvts.request(send_hotkey_list) File "C:Pythonlibsite-packagespyvtsvts.py", line 112, in request await self.websocket.send(json.dumps(request_msg)) File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 635, in send await self.ensure_open() File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 939, in ensure_open raise self.connection_closed_exc() websockets.exceptions.ConnectionClosedError: no close frame received or sent </code>
Exception in Tkinter callback
Traceback (most recent call last):
  File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 963, in transfer_data
    message = await self.read_message()
  File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 1033, in read_message
    frame = await self.read_data_frame(max_size=self.max_size)
  File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 1108, in read_data_frame
    frame = await self.read_frame(max_size)
  File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 1165, in read_frame
    frame = await Frame.read(
  File "C:Pythonlibsite-packageswebsocketslegacyframing.py", line 68, in read
    data = await reader(2)
  File "C:Pythonlibasynciostreams.py", line 723, in readexactly
    await self._wait_for_data('readexactly')
  File "C:Pythonlibasynciostreams.py", line 517, in _wait_for_data
    await self._waiter
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "C:Pythonlibtkinter__init__.py", line 1892, in __call__
    return self.func(*args)
  File "C:Pythonlibsite-packagescustomtkinterwindowswidgetsctk_button.py", line 554, in _clicked
    self._command()
  File "c:UsersHOME anyoneDocumentsAIVtuberProjectvoicevoxasync&ctk.py", line 42, in doing_def
    asyncio.run(doing())
  File "C:Pythonlibasynciorunners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:Pythonlibasynciobase_events.py", line 616, in run_until_complete
    return future.result()
  File "c:UsersHOME anyoneDocumentsAIVtuberProjectvoicevoxasync&ctk.py", line 38, in doing
    await myvts.request(send_hotkey_list)
  File "C:Pythonlibsite-packagespyvtsvts.py", line 112, in request
    await self.websocket.send(json.dumps(request_msg))
  File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 635, in send
    await self.ensure_open()
  File "C:Pythonlibsite-packageswebsocketslegacyprotocol.py", line 939, in ensure_open
    raise self.connection_closed_exc()
websockets.exceptions.ConnectionClosedError: no close frame received or sent

New contributor

user60739 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật