Spaces:
Runtime error
Runtime error
File size: 1,160 Bytes
1d02d7d 09299d3 1d02d7d 09299d3 1d02d7d 6dac605 09299d3 1d02d7d 09299d3 a21320c 09299d3 6dac605 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 | import os
from pydub import AudioSegment
def mixingAudio(sound1_path, sound2_path,position):
def check_and_convert(audio_file):
"""
Checks file format and converts to supported format if necessary.
"""
# Get file extension
extension = os.path.splitext(audio_file)[1].lower()
if extension not in (".mp3", ".wav", ".flac"):
# Convert to a supported format (e.g. mp3)
sound = AudioSegment.from_file(audio_file)
sound.export(os.path.splitext(audio_file)[0] + ".mp3", format="mp3")
# Update filename to the converted one
audio_file = os.path.splitext(audio_file)[0] + ".mp3"
return audio_file
# Check and convert audio files if needed
sound1_path = check_and_convert(sound1_path)
sound2_path = check_and_convert(sound2_path)
# Load audio files
sound1 = AudioSegment.from_file(sound1_path)
sound2 = AudioSegment.from_file(sound2_path)
# Mix sound2 with sound1, starting at 1000ms into sound1
output = sound1.overlay(sound2, position)
# Save the result (assuming mp3 format)
output.export(r"mixedAudio\mixed_haptic_audioFile.mp3", format="mp3")
return "The audio has been mixed." |