mirror of
https://github.com/EvolutionAPI/evolution-audio-converter.git
synced 2025-07-13 15:14:50 -06:00
fix(audio): ensure full WhatsApp compatibility for audio conversion (libopus, 48kHz, mono)
This commit is contained in:
parent
3feb0c7e1b
commit
170d5d8ad2
57
main.go
57
main.go
@ -159,19 +159,54 @@ func validateAPIKey(c *gin.Context) bool {
|
|||||||
|
|
||||||
func convertAudio(inputData []byte, format string) ([]byte, int, error) {
|
func convertAudio(inputData []byte, format string) ([]byte, int, error) {
|
||||||
var cmd *exec.Cmd
|
var cmd *exec.Cmd
|
||||||
|
|
||||||
switch format {
|
switch format {
|
||||||
case "mp3":
|
|
||||||
cmd = exec.Command("ffmpeg", "-i", "pipe:0",
|
|
||||||
"-ar", "44100", // sample rate
|
|
||||||
"-ac", "2", // canais (stereo)
|
|
||||||
"-b:a", "128k", // bitrate
|
|
||||||
"-c:a", "libmp3lame", // codec específico
|
|
||||||
"-f", "mp3", // formato
|
|
||||||
"pipe:1")
|
|
||||||
case "mp4":
|
case "mp4":
|
||||||
cmd = exec.Command("ffmpeg", "-i", "pipe:0", "-vn", "-c:a", "aac", "-b:a", "128k", "-f", "adts", "pipe:1")
|
// Special handling for MP4
|
||||||
|
cmd = exec.Command("ffmpeg", "-i", "pipe:0",
|
||||||
|
"-vn",
|
||||||
|
"-c:a",
|
||||||
|
"aac",
|
||||||
|
"-b:a", "128k",
|
||||||
|
"-f", "adts",
|
||||||
|
"pipe:1",
|
||||||
|
)
|
||||||
default:
|
default:
|
||||||
cmd = exec.Command("ffmpeg", "-i", "pipe:0", "-ac", "1", "-ar", "16000", "-c:a", "libopus", "-f", "ogg", "pipe:1")
|
// Any other audio format (e.g., .oga, .ogg, .mp3, .mp4, .m4a, .wav, etc.)
|
||||||
|
cmd = exec.Command("ffmpeg", "-i", "pipe:0",
|
||||||
|
"-f",
|
||||||
|
"ogg",
|
||||||
|
"-vn",
|
||||||
|
"-c:a",
|
||||||
|
"libopus",
|
||||||
|
"-avoid_negative_ts",
|
||||||
|
"make_zero",
|
||||||
|
"-b:a",
|
||||||
|
"128k",
|
||||||
|
"-ar",
|
||||||
|
"48000",
|
||||||
|
"-ac",
|
||||||
|
"1",
|
||||||
|
"-write_xing",
|
||||||
|
"0",
|
||||||
|
"-compression_level",
|
||||||
|
"10",
|
||||||
|
"-application",
|
||||||
|
"voip",
|
||||||
|
"-fflags",
|
||||||
|
"+bitexact",
|
||||||
|
"-flags",
|
||||||
|
"+bitexact",
|
||||||
|
"-id3v2_version",
|
||||||
|
"0",
|
||||||
|
"-map_metadata",
|
||||||
|
"-1",
|
||||||
|
"-map_chapters",
|
||||||
|
"-1",
|
||||||
|
"-write_bext",
|
||||||
|
"0",
|
||||||
|
"pipe:1",
|
||||||
|
)
|
||||||
}
|
}
|
||||||
outBuffer := bufferPool.Get().(*bytes.Buffer)
|
outBuffer := bufferPool.Get().(*bytes.Buffer)
|
||||||
errBuffer := bufferPool.Get().(*bytes.Buffer)
|
errBuffer := bufferPool.Get().(*bytes.Buffer)
|
||||||
@ -611,4 +646,4 @@ func main() {
|
|||||||
router.POST("/transcribe", transcribeOnly)
|
router.POST("/transcribe", transcribeOnly)
|
||||||
|
|
||||||
router.Run(":" + port)
|
router.Run(":" + port)
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user