伊地知ニジカ放送局だぬ゛ん゛. https://www.youtube.com/@deerjika
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

84 lines
2.5 KiB

  1. import pygame
  2. from pygame.locals import *
  3. import sys
  4. import pytchat
  5. import time
  6. import random
  7. from talk import Talk
  8. import subprocess
  9. from aques import Aques
  10. from playsound import playsound
  11. YOUTUBE_ID: str = 'Q0kSYNcu5Xk'
  12. class Main:
  13. @classmethod
  14. def main (cls) -> None:
  15. pygame.init ()
  16. screen: pygame.Surface = pygame.display.set_mode ((1024, 768))
  17. balloon = pygame.transform.scale (pygame.image.load ('talking.png'),
  18. (1024, 384))
  19. pygame.mixer.init (frequency = 44100)
  20. noon = pygame.mixer.Sound ('noon.wav')
  21. live_chat = pytchat.create (video_id = YOUTUBE_ID)
  22. system_font = pygame.font.SysFont ('notosanscjkjp', 24)
  23. user_font = pygame.font.SysFont ('notosanscjkjp', 32,
  24. italic = True)
  25. nizika_font = pygame.font.SysFont ('07nikumarufont', 50)
  26. while (True):
  27. screen.fill ((0, 255, 0))
  28. if live_chat.is_alive ():
  29. messages: list[str] = [c.message
  30. for c in live_chat.get ().items]
  31. if messages:
  32. message: str = random.choice (messages)
  33. answer: str = Talk.main (message)
  34. screen.blit (balloon, (0, 0))
  35. screen.blit (
  36. user_font.render ('> ' + message, True, (0, 0, 0)),
  37. (120, 70))
  38. screen.blit (
  39. nizika_font.render (answer, True, (192, 0, 0)),
  40. (100, 150))
  41. pygame.display.update ()
  42. noon.play ()
  43. time.sleep (2)
  44. wav: bytearray | None = Aques.main (answer)
  45. if wav is not None:
  46. with open ('./nizika_talking.wav', 'wb') as f:
  47. f.write (wav)
  48. playsound ('./nizika_talking.wav')
  49. time.sleep (10)
  50. screen.bilt (
  51. system_font.render (
  52. f'live_chat.is_alive () == {live_chat.is_alive ()}',
  53. True, (0, 0, 0)),
  54. (0, 0))
  55. pygame.display.update ()
  56. for event in pygame.event.get ():
  57. if event.type == QUIT:
  58. pygame.quit ()
  59. sys.exit ()
  60. if __name__ == '__main__':
  61. Main.main ()