Beispiel #1
0
    def __init__(self, file_name: str, streaming: bool = False):
        """ Create and load the sound. """
        self.file_name: str = ""
        self.wav_file: Union[soloud.WavStream, soloud.Wav]

        self.voice_handle = None  # needed for volume control

        if not _audiolib:
            return

        # If we should pull from local resources, replace with proper path
        if isinstance(file_name,
                      str) and str(file_name).startswith(":resources:"):
            import os
            path = os.path.dirname(os.path.abspath(__file__))
            file_name = f"{path}/resources/{file_name[11:]}"

        if not Path(file_name).is_file():
            raise FileNotFoundError(
                f"The sound file '{file_name}' is not a file or can't be read")
        self.file_name = file_name
        if streaming:
            self.wav_file = soloud.WavStream()
        else:
            self.wav_file = soloud.Wav()
        self.wav_file.load(self.file_name)
    def __init__(self, file_name: Union[str, Path], streaming: bool = False):
        """ Create and load the sound. """
        self.file_name: str = ""
        self.wav_file: Union[soloud.WavStream, soloud.Wav]

        self.voice_handle = None  # needed for volume control

        if not _audiolib:
            return

        # If we should pull from local resources, replace with proper path
        file_name = resolve_resource_path(file_name)

        if not Path(file_name).is_file():
            raise FileNotFoundError(
                f"The sound file '{file_name}' is not a file or can't be read")
        self.file_name = str(file_name)

        if streaming:
            self.wav_file = soloud.WavStream()
        else:
            self.wav_file = soloud.Wav()
        self.wav_file.load(self.file_name)