|
26 | 26 | from io import BytesIO |
27 | 27 | import librosa |
28 | 28 | import soundfile as sf |
29 | | -from pydub.effects import speedup |
30 | 29 | from pydub.playback import play |
31 | 30 | import sounddevice as sd |
32 | 31 | #pynanosvg |
@@ -547,6 +546,11 @@ def constrain(val, min_val, max_val): |
547 | 546 | musicintrofilepath = "" |
548 | 547 | pymusictype = "" |
549 | 548 |
|
| 549 | +def pitch_shift(sound, semitones): |
| 550 | + new_sample_rate = int(sound.frame_rate * (2.0 ** (semitones / 12.0))) |
| 551 | + shifted = sound._spawn(sound.raw_data, overrides={'frame_rate': new_sample_rate}) |
| 552 | + return shifted.set_frame_rate(sound.frame_rate) |
| 553 | + |
550 | 554 | def PlayMusic(musNum): |
551 | 555 | pygame.mixer.music.stop() |
552 | 556 | global pygamemixermusic, musicfilepath, musicintrofilepath |
@@ -582,9 +586,13 @@ def PlayMusic(musNum): |
582 | 586 | musicfilepath = "./assets/audio/INOSSI - Got you-loop 44100.wav" |
583 | 587 | musicintrofilepath = "./assets/audio/INOSSI - Got you-start 44100.wav" |
584 | 588 | # Load audio file |
| 589 | + pygame.mixer.music.load(musicintrofilepath) |
585 | 590 | music1 = AudioSegment.from_file(musicintrofilepath) |
586 | 591 | music2 = AudioSegment.from_file(musicfilepath) |
587 | | - |
| 592 | + |
| 593 | + shifted_sound1 = pitch_shift(music1, 3) # 4 semitones up |
| 594 | + shifted_sound2 = pitch_shift(music2, 3) # 4 semitones up |
| 595 | + play(shifted_sound1) |
588 | 596 | pygame.mixer.music.load(musicintrofilepath) |
589 | 597 | pygame.mixer.music.set_volume(Decimal(pygamemixermusic)) |
590 | 598 | pygame.mixer.music.set_volume(min(1.0, pygame.mixer.music.get_volume() * 1.1)) |
|
0 commit comments