Skip to content

Instantly share code, notes, and snippets.

@sharl
Created November 30, 2023 07:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sharl/08038e9f03519982a056f8d40661d014 to your computer and use it in GitHub Desktop.
Save sharl/08038e9f03519982a056f8d40661d014 to your computer and use it in GitHub Desktop.
ドラゴンクエストⅩ 第5回 みんなでカジノレイド 大挑戦! の進捗をずんだもんがしゃべってくれるやつ
# -*- coding: utf-8 -*-
import json
import requests
import pyaudio
host = '127.0.0.1'
port = 50021
def vvox(text):
params = {
'text': text,
'speaker': 3, # ずんだもん
}
query = requests.post(
f'http://{host}:{port}/audio_query',
params=params,
)
synthesis = requests.post(
f'http://{host}:{port}/synthesis',
headers={'Content-Type': 'application/json'},
params=params,
data=json.dumps(query.json()),
)
voice = synthesis.content
pya = pyaudio.PyAudio()
stream = pya.open(
format=pyaudio.paInt16, # 16bit
channels=1, # モノラル
rate=24000, # 設定の「音声のサンプリングレート」に合わせる デフォルトは24000
output=True,
)
stream.write(voice)
stream.stop_stream()
stream.close()
pya.terminate()
if __name__ == '__main__':
import time
from bs4 import BeautifulSoup
base_url = 'https://hiroba.dqx.jp/sc/event/casinoraid005'
rainbows = [
'レインボージュエル',
'レインボートーテム',
'レインボーゴーレム',
'レインボースライム',
]
pre_text = ''
while True:
try:
r = requests.get(base_url, timeout=10)
if r and r.status_code == 200:
soup = BeautifulSoup(r.content, 'html.parser')
missions = soup.find_all(class_='mission_list_bottom')
text = ''
for i, mission in enumerate(missions):
line = mission.text.strip()
defeats = line.split(chr(0xa0))[0]
rate = int(int(defeats.replace(',', '')) * 100 / 500000)
text += f'{rainbows[i]} {rate}% '
if text != pre_text:
vvox(text)
pre_text = text
except Exception:
pass
time.sleep(300)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment