I am generating dialog between characters and then merging them together with ffmpeg. The audio has weird clipping and jumping sounds and sounds the audio does not sound very natural. This would seem to be a process that happens all the time on cartesia.
I also notice that on the generated mp3s I get from cartesia, they sometimes have different background noises, so when you merge them they would not merge nicely anyway, so it seems to be 2 issues happening here.
Is there a tutorial,docs, or official way to merge cartesia audio to make a longer audio file?
Here is the code I use now in ruby:
# Create list of files with silence between them
mp3_files = Dir.glob("#{dir}/*.mp3").reject { |f| f == silence_file }
.sort_by { |file| file.scan(/\d+|\D+/).map { |s| s =~ /\d+/ ? s.to_i : s } }
output_file = "merged_#{id}.mp3"
Tempfile.open('mp3_list') do |tempfile|
mp3_files.each_with_index do |file, index|
tempfile.puts "file '#{File.expand_path(file)}'"
# Add silence after each file except the last one
if index < mp3_files.length - 1
tempfile.puts "file '#{File.expand_path(silence_file)}'"
end
end
tempfile.flush
# Merge the mp3 files using ffmpeg
cmd = "ffmpeg -f concat -safe 0 -i #{tempfile.path} -c:a libmp3lame -q:a 2 #{output_file}"
puts cmd
system cmd
end