예제 #1
0
 def load_subs(self, subs_path):
     with open(subs_path) as subs:
         self._subs = SubRip.parse(subs.read())
     self._sub = None
     self._emit_sub_changed_new_thread()
예제 #2
-1
    def open(self, audio):
        self.pause()
        path = PurePath(audio)
        if path.suffix == ".wav":
            self._audio = wave.open(audio, "rb")
        else:
            self._audio = None
            raise ValueError("Unsupported format " + path.suffix)
        self._length = self._audio.getnframes() / self._audio.getframerate() / self._audio.getnchannels() * 1000
        self._device.setchannels(self._audio.getnchannels())
        self._device.setrate(self._audio.getframerate())

        # 8bit is unsigned in wav files
        if self._audio.getsampwidth() == 1:
            self._device.setformat(alsaaudio.PCM_FORMAT_U8)
        # Otherwise we assume signed data, little endian
        elif self._audio.getsampwidth() == 2:
            self._device.setformat(alsaaudio.PCM_FORMAT_S16_LE)
        elif self._audio.getsampwidth() == 3:
            self._device.setformat(alsaaudio.PCM_FORMAT_S24_LE)
        elif self._audio.getsampwidth() == 4:
            self._device.setformat(alsaaudio.PCM_FORMAT_S32_LE)
        else:
            raise ValueError('Unsupported format')

        self._device.setperiodsize(self._CHUNK)

        try:
            with open(str(path.with_suffix(".srt"))) as subs:
                self._subs = SubRip.parse(subs.read())
        except Exception:
            self._subs = None
        self._emit_sub_changed_new_thread()