예제 #1
0
파일: sound.py 프로젝트: hgiesel/anki
    def play(self, tag: AVTag, on_done: OnDoneCallback) -> None:
        assert isinstance(tag, SoundOrVideoTag)
        self._on_done = on_done
        filename = hooks.media_file_filter(tag.filename)
        path = os.path.join(self.media_folder, filename)

        self.command("loadfile", path, "replace", "pause=no")
        gui_hooks.av_player_did_begin_playing(self, tag)
예제 #2
0
파일: sound.py 프로젝트: shaunren/anki
    def play(self, tag: AVTag, on_done: OnDoneCallback) -> None:
        assert isinstance(tag, SoundOrVideoTag)
        self._on_done = on_done
        filename = hooks.media_file_filter(tag.filename)
        path = os.path.join(os.getcwd(), filename)

        self.command("loadfile", path, "append-play")
        gui_hooks.av_player_did_begin_playing(self, tag)
예제 #3
0
    def _wait_for_termination(self, tag: AVTag):
        self._taskman.run_on_main(
            lambda: gui_hooks.av_player_did_begin_playing(self, tag))

        while True:
            with self._lock:
                # if .stop() timed out, another thread may run when
                # there is no process
                if not self._process:
                    self._process = None
                    self._terminate_flag = False
                    return

                # should we abort playing?
                if self._terminate_flag:
                    self._process.terminate()
                    self._process = None
                    self._terminate_flag = False
                    raise PlayerInterrupted()

                # wait for completion
                try:
                    self._process.wait(0.1)
                    if self._process.returncode != 0:
                        print(
                            f"player got return code: {self._process.returncode}"
                        )
                    self._process = None
                    self._terminate_flag = False
                    return
                except subprocess.TimeoutExpired:
                    pass
예제 #4
0
파일: sound.py 프로젝트: evandroforks/anki
    def _wait_for_termination(self, tag: AVTag) -> None:
        self._taskman.run_on_main(
            lambda: gui_hooks.av_player_did_begin_playing(self, tag)
        )

        while True:
            # should we abort playing?
            if self._terminate_flag:
                self._process.terminate()
                self._process.wait(1)
                if self._process.stdin:
                    self._process.stdin.close()
                self._process = None
                return

            # wait for completion
            try:
                self._process.wait(0.1)
                if self._process.returncode != 0:
                    print(f"player got return code: {self._process.returncode}")
                if self._process.stdin:
                    self._process.stdin.close()
                self._process = None
                return
            except subprocess.TimeoutExpired:
                # process still running, repeat loop
                pass
예제 #5
0
파일: tts.py 프로젝트: DexDex1515/anki
        def _play(self, tag: AVTag) -> None:
            assert isinstance(tag, TTSTag)
            match = self.voice_for_tag(tag)
            assert match
            voice = cast(WindowsRTVoice, match.voice)

            self._taskman.run_on_main(
                lambda: gui_hooks.av_player_did_begin_playing(self, tag))
            asyncio.run(self.speakText(tag, voice.id))
예제 #6
0
        def _play(self, tag: AVTag) -> None:
            assert isinstance(tag, TTSTag)
            match = self.voice_for_tag(tag)
            assert match
            voice = cast(WindowsVoice, match.voice)

            try:
                native_voice = voice.handle
                self.speaker.Voice = native_voice
                self.speaker.Speak(tag.field_text, 1)
                gui_hooks.av_player_did_begin_playing(self, tag)

                # wait 100ms
                while not self.speaker.WaitUntilDone(100):
                    if self._terminate_flag:
                        # stop playing
                        self.speaker.Skip("Sentence", 2**15)
                        return
            finally:
                self._terminate_flag = False
예제 #7
0
    def _wait_for_termination(self, tag: AVTag):
        self._taskman.run_on_main(
            lambda: gui_hooks.av_player_did_begin_playing(self, tag))

        try:
            while True:
                try:
                    self._process.wait(0.1)
                    if self._process.returncode != 0:
                        print(
                            f"player got return code: {self._process.returncode}"
                        )
                    return
                except subprocess.TimeoutExpired:
                    pass
                if self._terminate_flag:
                    self._process.terminate()
                    raise PlayerInterrupted()
        finally:
            self._process = None
            self._terminate_flag = False