示例#1
0
 def test_4_add_note_two_notes_simultaneous(self):
     segment = AudioSegment.empty()
     segment = add_piano_note(segment, 24, 0, 2000)
     segment = add_piano_note(segment, 68, 1000, 500)
     segment.export(PREFIX +
                    "/generated/test_4_add_note_two_notes_simultaneous.wav",
                    format="wav")
     expected = AudioSegment.from_wav(
         PREFIX + '/Audio/test_4_add_note_two_notes_simultaneous.wav')
     self.assertTrue(
         len(segment) == len(expected),
         f"the melody should be same length as test_4_add_note_two_notes_simultaneous.wav, expected {len(expected)}, got {len(segment)}"
     )
     self.assertTrue(
         expected == segment,
         "Generated audio does not match the expected. Compare your generated sample to test_4_add_note_two_notes_simultaneous.wav to debug."
     )
示例#2
0
 def test_4_add_one_note_after_one_note(self):
     # one note segment, add another note right after it
     empty_segment = AudioSegment.empty()
     one_note_segment = add_piano_note(empty_segment, 48, 0, 1000)
     segment = add_piano_note(one_note_segment, 50, 1000, 1000)
     segment.export(PREFIX +
                    '/generated/test_4_add_note_after_one_note.wav',
                    format='wav')
     expected = AudioSegment.from_wav(
         PREFIX + '/Audio/test_4_add_note_after_one_note.wav')
     self.assertTrue(
         len(segment) == len(expected),
         f"the melody should be same length as test_4_add_note_after_one_note.wav, expected {len(expected)}, got {len(segment)}"
     )
     self.assertTrue(
         expected == segment,
         "Generated audio does not match the expected. Compare your generated sample to test_4_add_note_after_one_note.wav to debug."
     )
示例#3
0
 def test_4_add_one_note_in_middle(self):
     # add a note in the middle
     empty_segment = AudioSegment.empty()
     segment = add_piano_note(empty_segment, 48, 0, 1000)
     segment = add_piano_note(segment, 50, 1000, 1000)
     segment = add_piano_note(segment, 52, 2000, 1000)
     segment = add_perc_note(segment, "snare", 1000)
     segment.export(PREFIX + '/generated/test_4_add_one_note_in_middle.wav',
                    format='wav')
     expected = AudioSegment.from_wav(
         PREFIX + '/Audio/test_4_add_one_note_in_middle.wav')
     self.assertTrue(
         len(segment) == len(expected),
         f"the melody should be same length as test_4_add_one_note_in_middle.wav, expected {len(expected)}, got {len(segment)}"
     )
     self.assertTrue(
         expected == segment,
         "Generated audio does not match the expected. Compare your generated sample to test_4_add_one_note_in_middle.wav to debug."
     )
示例#4
0
    def test_4_add_note_multiple(self):
        # TODO this is 2 test cases
        scale = build_major_scale(root_pitch=30, num_octaves=3)
        dur = bpm_to_beat_len(240)
        segment = AudioSegment.silent(dur * len(scale))
        segment.export(PREFIX + "/generated/test_4_add_note_multiple.wav",
                       format="wav")
        for i in range(len(scale)):
            if i % 2 == 0:
                add_piano_note(segment, scale[i], i * dur, dur * 2)
        if len(segment) == 0:
            self.fail("scale_to_playable_melody not yet implemented")
            return
        self.assertTrue(
            len(segment) == len(scale) * dur,
            f"the playable melody should be same length as test_4_add_note_multiple.wav, expected {len(scale)*dur}, got {len(segment)}"
        )

        expected = AudioSegment.from_wav(PREFIX +
                                         "/Audio/test_4_add_note_multiple.wav")
        self.assertTrue(
            expected == segment,
            "Generated audio does not match the expected. Compare your generated samples to test_4_add_note_multiple.wav to debug."
        )
示例#5
0
 def test_4_add_single_note_to_empty_piano(self):
     # add a single note to empty, piano
     empty_segment = AudioSegment.empty()
     segment = add_piano_note(empty_segment, 48, 0, 1000)
     segment.export(PREFIX +
                    '/generated/test_4_add_single_note_to_empty_piano.wav',
                    format='wav')
     expected = AudioSegment.from_wav(
         PREFIX + '/Audio/test_4_add_single_note_to_empty_piano.wav')
     self.assertTrue(
         len(segment) == len(expected),
         f"the melody should be same length as test_4_add_single_note_to_empty_piano.wav, expected {len(expected)}, got {len(segment)}"
     )
     self.assertTrue(
         expected == segment,
         "Generated audio does not match the expected. Compare your generated sample to test_4_add_single_note_to_empty_piano.wav to debug."
     )
示例#6
0
 def test_4_add_note_multiple_long(self):
     mary = [(52, 0, 500), (50, 500, 500), (48, 1000, 500), (50, 1500, 500),
             (52, 2000, 500), (52, 2500, 500), (52, 3000, 1000),
             (50, 4000, 500), (50, 4500, 500), (50, 5000, 1000),
             (52, 6000, 500), (55, 6500, 500), (55, 7000, 1000)]
     dur = bpm_to_beat_len(120)
     segment = AudioSegment.silent(dur * len(mary))
     for pitch, start, b in mary:
         segment = add_piano_note(segment, pitch, start, b)
     segment.export(PREFIX + "/generated/test_4_add_note_multiple_long.wav",
                    format="wav")
     expected = AudioSegment.from_wav(
         PREFIX + "/Audio/test_4_add_note_multiple_long.wav")
     self.assertTrue(
         len(segment) == len(expected),
         f"the melody should be same length as test_4_add_note_multiple_long.wav, expected {len(expected)}, got {len(segment)}"
     )
     self.assertTrue(
         expected == segment,
         "Generated audio does not match the expected. Compare your generated samples to test_4_add_note_multiple_long.wav to debug."
     )