To merge two audio files as described, you can use the ffmpeg command line tool or the moviepy Python library, which acts as a wrapper for ffmpeg. Below I provide an example using moviepy.
First, install moviepy if you haven't already by running:
pip install moviepy
Here's a Python script that does what you're asking for:
from moviepy.editor import AudioFileClip, CompositeAudioClip
# Load your audio files
long_clip = AudioFileClip("long.mp3")
short_clip = AudioFileClip("short.mp3")
# Set the start time for the short clip (10 seconds into the long clip)
short_clip = short_clip.set_start(10)
# Calculate the duration of the long clip to make sure the composite is as long as the long.mp3
duration_of_long_clip = long_clip.duration
# Overlay the short clip on top of the long clip
composite = CompositeAudioClip([long_clip, short_clip.set_duration(duration_of_long_clip - 10)])
# Write the result to a file. The duration will be the same as the long clip
composite.write_audiofile("merged.mp3", codec='libmp3lame')
This script will create a new audio file called merged.mp3 which starts with the long.mp3 file and then overlays short.mp3 starting at 10 seconds in. The final audio will have the duration of the longer audio file, as you wanted.
Please ensure that you have ffmpeg installed on your system since moviepy uses it under the hood. You can download ffmpeg from the official website or install it via a package manager like apt on Ubuntu or brew on macOS.