伊地知ニジカ放送局だぬ゛ん゛. 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.1 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
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. noon.play ()
  40. wav: bytearray | None = Aques.main (answer)
  41. if wav is not None:
  42. with open ('./nizika_talking.wav', 'wb') as f:
  43. f.write (wav)
  44. playsound ('./nizika_talking.wav')
  45. time.sleep (10)
  46. pygame.display.update ()
  47. for event in pygame.event.get ():
  48. if event.type == QUIT:
  49. pygame.quit ()
  50. sys.exit ()
  51. if __name__ == '__main__':
  52. Main.main ()