def test_ambiguous(self):
     audio_block = AudioBlock()
     track1 = audio_block.create_track(primary=True)
     track2 = audio_block.create_track(primary=True)
     sound_1 = track1.create_sound(
         file_url=
         "https://inoft-vocal-engine-web-test.s3.eu-west-3.amazonaws.com/Moby+-+Creep+(Radiohead's+cover)+-+trimmed.mp3",
         player_start_time=track1.player_start_time,
         player_end_time=track2.player_start_time + 21)
     sound_2 = track2.create_sound(
         local_filepath=os.path.join(self.audio_samples_dirpath,
                                     "hop_short_mp3.mp3"),
         player_start_time=track1.player_start_time,
         player_end_time=track2.player_start_time + 20)
     sound_3 = track2.create_sound(
         local_filepath=os.path.join(
             self.audio_samples_dirpath,
             "synthchopinfantaisieimpromptu120bpm1.mp3"),
         player_start_time=sound_1.player_start_time + 5,
         player_end_time=sound_2.player_end_time - 2)
     out_filepath = os.path.join(self.audio_dist_dirpath,
                                 "test_relationships_ambiguous")
     response_data: dict = audio_block.manual_render(
         **ALEXA_MANUAL_RENDER_CLOUD_KWARGS,
         out_filepath=out_filepath,
         format_type=AudioBlock.FORMAT_TYPE_MP3)
     if click.confirm("Open file ?"):
         webbrowser.open(response_data['fileUrl'])
         self.assertTrue(click.confirm(text="Everything's good ?"))
    def test_unusual_but_working_relations(self):
        audio_block = AudioBlock()
        track1 = audio_block.create_track(primary=True)
        track2 = audio_block.create_track(primary=True)
        sound_1 = track2.create_sound(
            local_filepath=os.path.join(self.audio_samples_dirpath,
                                        "hop_short_mp3.mp3"),
            player_start_time=track1.player_start_time,
            player_end_time=track2.player_start_time + 20)

        # sound_2 is dependant on sound_1.player_start_time

        from inoft_vocal_framework.audio_editing.audio_effects import TremoloEffect
        sound_2 = track2.create_sound(
            local_filepath=os.path.join(
                self.audio_samples_dirpath,
                "synthchopinfantaisieimpromptu120bpm1.mp3"),
            player_start_time=sound_1.player_end_time + 5,
            player_end_time=track2.player_start_time + 25)

        # We force sound_1 to be dependant to sound_2
        sound_1._player_start_time = sound_2.player_start_time + 3

        out_filepath = os.path.join(self.audio_dist_dirpath,
                                    "test_broken_relations")
        response_data: dict = audio_block.manual_render(
            **ALEXA_MANUAL_RENDER_CLOUD_KWARGS,
            out_filepath=out_filepath,
            format_type=AudioBlock.FORMAT_TYPE_MP3)
        if click.confirm("Open file ?"):
            webbrowser.open(response_data['fileUrl'])
            self.assertTrue(click.confirm(text="Everything's good ?"))
    def test_clip_formats_and_mono_mp3(self):
        audio_block_1 = AudioBlock()
        track_1 = audio_block_1.create_track()

        sound_1 = track_1.create_sound(
            local_filepath="C:/Users/LABOURDETTE/Downloads/Isaac Delusion — How Much (You Want Her) 2017 (LYRICS VIDEO).mp3",
            file_start_time=0,
            file_end_time=10,
            player_start_time=track_1.player_start_time,
            player_end_time=track_1.player_start_time + 5
        )
        sound_2 = track_1.create_sound(
            local_filepath=os.path.join(self.audio_samples_dirpath, "hop_short_wav_16bit.wav"),
            file_start_time=20,
            file_end_time=25,
            player_start_time=sound_1.end_time + 1,
            player_end_time=sound_1.end_time + 6
        )
        sound_3 = track_1.create_sound(
            local_filepath=os.path.join(self.audio_samples_dirpath, "hop_short_mono_mp3.mp3"),
            file_start_time=20,
            file_end_time=25,
            player_start_time=sound_2.end_time + 1,
            player_end_time=sound_2.end_time + 6
        )

        out_filepath = os.path.join(self.audio_dist_dirpath, f"test_clip_formats_and_mono_mp3.mp3")
        file_url = audio_block_1.manual_render(**ALEXA_BASE_MANUAL_RENDER_KWARGS, out_filepath=out_filepath, format_type=AudioBlock.FORMAT_TYPE_MP3)
        if click.confirm("Open file ?"):
            os.startfile(out_filepath)
            self.assertTrue(click.confirm(text="Everything's good ?"))
    def test_multi_clips(self):
        audio_block_1 = AudioBlock()
        track_1 = audio_block_1.create_track()
        from inoft_vocal_framework import Speech
        music_1 = track_1.create_sound(
            # engine_file_key="how_much_you_want_her_20s",
            local_filepath="C:/Users/LABOURDETTE/Downloads/Isaac Delusion — How Much (You Want Her) 2017 (LYRICS VIDEO).mp3",
            file_start_time=20,
            file_end_time=25,
            player_start_time=track_1.player_start_time + 10,
            player_end_time=track_1.player_start_time + 20
        )

        from inoft_vocal_engine.speech_synthesis.polly import VOICES
        voice_sound = track_1.create_speech(
            text="Je suis un test d'audio dynamique ?",
            voice_key=VOICES.French_France_Female_CELINE.id,
            player_start_time=track_1.player_start_time + 21,
        )

        music_2 = track_1.create_sound(
            local_filepath="C:/Users/LABOURDETTE/Downloads/ANRI - I Can't Stop The Loneliness.mp3",
            player_start_time=voice_sound.end_time + 5,
            player_end_time=voice_sound.end_time + 20
        )

        out_filepath = os.path.join(self.audio_dist_dirpath, f"multi_clip_test.mp3")
        file_url = audio_block_1.manual_render(**ALEXA_BASE_MANUAL_RENDER_KWARGS, out_filepath=out_filepath, format_type=AudioBlock.FORMAT_TYPE_MP3)
        if click.confirm("Open file ?"):
            os.startfile(out_filepath)
            self.assertTrue(click.confirm(text="Everything's good ?"))
    def test_clip_reuse(self):
        filepath = os.path.join(self.audio_samples_dirpath, "hop_short_wav_16bit.wav")
        audio_block_1 = AudioBlock()
        track_1 = audio_block_1.create_track()

        sound_1 = track_1.create_sound(
            local_filepath=filepath,
            file_start_time=20,
            file_end_time=30,
            player_start_time=track_1.player_start_time,
            player_end_time=track_1.player_start_time + 5
        )
        sound_2 = track_1.create_sound(
            local_filepath=filepath,
            file_start_time=10,
            file_end_time=18,
            player_start_time=sound_1.end_time + 1,
            player_end_time=sound_1.end_time + 6
        )
        sound_3 = track_1.create_sound(
            local_filepath=filepath,
            file_start_time=30,
            file_end_time=35,
            player_start_time=sound_2.end_time + 1,
            player_end_time=sound_2.end_time + 6
        )

        out_filepath = os.path.join(self.audio_dist_dirpath, f"test_clip_reuse.mp3")
        file_url = audio_block_1.manual_render(**ALEXA_BASE_MANUAL_RENDER_KWARGS, out_filepath=out_filepath, format_type=AudioBlock.FORMAT_TYPE_MP3)
        if click.confirm("Open file ?"):
            os.startfile(out_filepath)
            self.assertTrue(click.confirm(text="Everything's good ?"))
 def test_simple(self):
     audio_block = AudioBlock()
     track1 = audio_block.create_track(primary=True)
     track2 = audio_block.create_track(primary=True)
     track1.create_sound(
         file_url=
         "https://inoft-vocal-engine-web-test.s3.eu-west-3.amazonaws.com/Moby+-+Creep+(Radiohead's+cover)+-+trimmed.mp3",
         player_start_time=track1.player_start_time,
         player_end_time=track2.player_start_time + 20)
     track2.create_sound(local_filepath=os.path.join(
         self.audio_samples_dirpath, "hop_short_wav_16bit.wav"),
                         player_start_time=track1.player_start_time,
                         player_end_time=track2.player_start_time + 21)
     file_url: Optional[str] = audio_block.manual_render(
         **ALEXA_MANUAL_RENDER_CLOUD_KWARGS,
         format_type=AudioBlock.FORMAT_TYPE_MP3)
     if click.confirm("Open file ?"):
         webbrowser.open(file_url)
         self.assertTrue(click.confirm(text="Everything's good ?"))
    def test_first_track_empty(self):
        audio_block = AudioBlock()
        empty_first_track = audio_block.create_track()
        track_music = audio_block.create_track()
        music = track_music.create_sound(
            local_filepath=os.path.join(self.audio_samples_dirpath, "hop_short_wav_16bit.wav"),
            player_start_time=track_music.player_start_time + 2,
            volume=100
        )
        from inoft_vocal_framework.audio_editing.audio_effects import EqualizerEffect
        # music_2.add_effect(EqualizerEffect())
        """from inoft_vocal_framework.audio_editing.audio_effects import TremoloEffect
        music_2.add_effect(TremoloEffect(gain=1, speed=0.3))"""
        """audio_block.create_track().create_sound(
            local_filepath="F:\Inoft/anvers_1944_project\inoft_vocal_framework\plotters-spectrogram-main/example.wav",
            player_start_time=container_track.player_start_time
        )"""

        out_filepath = os.path.join(self.audio_dist_dirpath, f"test_first_track_empty.wav")
        file_url = audio_block.manual_render(**ALEXA_BASE_MANUAL_RENDER_KWARGS, out_filepath=out_filepath, format_type=AudioBlock.FORMAT_TYPE_WAV)
        if click.confirm("Open file ?"):
            os.startfile(out_filepath)
            self.assertTrue(click.confirm(text="Everything's good ?"))
 def play_audio_block(self,
                      audio_block: AudioBlock,
                      num_channels: 1 or 2 = 1,
                      sample_rate: 24000 or 22050 or 16000 = 24000) -> bool:
     # todo: stop using the infrastructure_speech_synthesis setting, and use a kind of 'audio_engine' setting ?
     override_engine_base_url = INFRASTRUCTURE_TO_BASE_URL.get(
         self._parent_handler_input.settings.
         infrastructure_speech_synthesis, '')
     # todo: only include if the engine is not INFRASTRUCTURE_ENGINE
     file_url = audio_block.manual_render(
         engine_account_id=self._parent_handler_input.settings.
         engine_account_id,
         engine_project_id=self._parent_handler_input.settings.
         engine_project_id,
         engine_api_key=self._parent_handler_input.settings.engine_api_key,
         override_engine_base_url=override_engine_base_url,
         num_channels=num_channels,
         sample_rate=sample_rate,
         bitrate=48,
         out_filepath="null",
         format_type="mp3")
     # todo: make out_filepath argument optional
     self.say_ssml(f'<audio src="{file_url}" />')
     return True  # todo: return False is rendering failed