伊地知ニジカ放送局だぬ゛ん゛. 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.

main.py 2.2 KiB

11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
11 months ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 = 'aq3QwuYz-KU'
  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. user_font = pygame.font.SysFont ('notosanscjkjp', 32,
  23. italic = True)
  24. nizika_font = pygame.font.SysFont ('07nikumarufont', 50)
  25. while (True):
  26. screen.fill ((0, 255, 0))
  27. if live_chat.is_alive ():
  28. messages: list[str] = [c.message
  29. for c in live_chat.get ().items]
  30. if messages:
  31. message: str = random.choice (messages)
  32. answer: str = Talk.main (message)
  33. screen.blit (balloon, (0, 0))
  34. screen.blit (user_font.render ('> ' + message, True,
  35. (0, 0, 0)),
  36. (120, 70))
  37. screen.blit (nizika_font.render (
  38. answer, True, (192, 0, 0)), (100, 150))
  39. pygame.display.update ()
  40. noon.play ()
  41. time.sleep (2)
  42. wav: bytearray | None = Aques.main (answer)
  43. if wav is not None:
  44. with open ('./nizika_talking.wav', 'wb') as f:
  45. f.write (wav)
  46. playsound ('./nizika_talking.wav')
  47. time.sleep (10)
  48. pygame.display.update ()
  49. for event in pygame.event.get ():
  50. if event.type == QUIT:
  51. pygame.quit ()
  52. sys.exit ()
  53. if __name__ == '__main__':
  54. Main.main ()