Browse Source

#34

ai-migration
みてるぞ 2 weeks ago
parent
commit
4ad5868b63
1 changed files with 14 additions and 11 deletions
  1. +14
    -11
      test.py

+ 14
- 11
test.py View File

@@ -7,8 +7,8 @@ import sys
import wave import wave
from datetime import datetime, timedelta from datetime import datetime, timedelta
from enum import Enum, auto from enum import Enum, auto
from typing import Callable, TypedDict
from io import BytesIO from io import BytesIO
from typing import Callable, TypedDict


import cv2 import cv2
import emoji import emoji
@@ -20,7 +20,6 @@ import pytchat
import requests import requests
from cv2 import VideoCapture from cv2 import VideoCapture
from ephem import Moon, Observer, Sun from ephem import Moon, Observer, Sun
from pydub import AudioSegment
from pygame import Rect, Surface from pygame import Rect, Surface
from pygame.font import Font from pygame.font import Font
from pygame.mixer import Sound from pygame.mixer import Sound
@@ -53,7 +52,6 @@ def main (
x = CWindow.WIDTH * 3 / 4, x = CWindow.WIDTH * 3 / 4,
y = CWindow.HEIGHT - 120, y = CWindow.HEIGHT - 120,
balloon = balloon) balloon = balloon)
Video (game, 'snack_time.mp4').play ()
CurrentTime (game, SYSTEM_FONT) CurrentTime (game, SYSTEM_FONT)
try: try:
broadcast = Broadcast (os.environ['BROADCAST_CODE']) broadcast = Broadcast (os.environ['BROADCAST_CODE'])
@@ -752,14 +750,10 @@ class Broadcast:
return random.choice (chats) return random.choice (chats)




class NicoVideo (Video):
...


class Video (GameObject): class Video (GameObject):
fps: int fps: int
pausing: bool = False pausing: bool = False
sound: Sound
sound: Sound | None
surfaces: list[Surface] surfaces: list[Surface]


def __init__ ( def __init__ (
@@ -776,9 +770,13 @@ class Video (GameObject):
def _create_sound ( def _create_sound (
self, self,
path: str, path: str,
) -> Sound:
) -> Sound | None:
bytes_io = BytesIO () bytes_io = BytesIO ()
audio = AudioSegment.from_file (path, format = path.split ('.')[-1])
try:
from pydub import AudioSegment
audio = AudioSegment.from_file (path, format = path.split ('.')[-1])
except ModuleNotFoundError:
return None
audio.export (bytes_io, format = 'wav') audio.export (bytes_io, format = 'wav')
bytes_io.seek (0) bytes_io.seek (0)
return pygame.mixer.Sound (bytes_io) return pygame.mixer.Sound (bytes_io)
@@ -843,7 +841,8 @@ class Video (GameObject):
) -> None: ) -> None:
self.enabled = True self.enabled = True
self.pausing = False self.pausing = False
self.sound.play ()
if self.sound is not None:
self.sound.play ()


def stop ( def stop (
self, self,
@@ -872,6 +871,10 @@ class Video (GameObject):
super ().update () super ().update ()




class NicoVideo (Video):
...


def fetch_bytes_from_url ( def fetch_bytes_from_url (
url: str, url: str,
) -> bytes | None: ) -> bytes | None:


Loading…
Cancel
Save