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
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
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
user60739 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.