mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-07-16 20:22:54 -06:00
feat: convert audio with api
This commit is contained in:
parent
34769e2293
commit
e986768716
@ -248,6 +248,9 @@ S3_USE_SSL=true
|
|||||||
# S3_USE_SSL=true
|
# S3_USE_SSL=true
|
||||||
# S3_REGION=eu-south
|
# S3_REGION=eu-south
|
||||||
|
|
||||||
|
# Evolution Audio Converter - Environment variables - https://github.com/EvolutionAPI/evolution-audio-converter
|
||||||
|
API_AUDIO_CONVERTER=http://localhost:4040/process-audio
|
||||||
|
|
||||||
# Define a global apikey to access all instances.
|
# Define a global apikey to access all instances.
|
||||||
# OBS: This key must be inserted in the request header to create an instance.
|
# OBS: This key must be inserted in the request header to create an instance.
|
||||||
AUTHENTICATION_API_KEY=429683C4C977415CAAFCCE10F7D57E11
|
AUTHENTICATION_API_KEY=429683C4C977415CAAFCCE10F7D57E11
|
||||||
|
@ -125,6 +125,7 @@ import { isArray, isBase64, isURL } from 'class-validator';
|
|||||||
import { randomBytes } from 'crypto';
|
import { randomBytes } from 'crypto';
|
||||||
import EventEmitter2 from 'eventemitter2';
|
import EventEmitter2 from 'eventemitter2';
|
||||||
import ffmpeg from 'fluent-ffmpeg';
|
import ffmpeg from 'fluent-ffmpeg';
|
||||||
|
import FormData from 'form-data';
|
||||||
import { readFileSync } from 'fs';
|
import { readFileSync } from 'fs';
|
||||||
import Long from 'long';
|
import Long from 'long';
|
||||||
import mime from 'mime';
|
import mime from 'mime';
|
||||||
@ -2631,6 +2632,27 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async processAudio(audio: string): Promise<Buffer> {
|
public async processAudio(audio: string): Promise<Buffer> {
|
||||||
|
if (process.env.API_AUDIO_CONVERTER) {
|
||||||
|
const formData = new FormData();
|
||||||
|
|
||||||
|
if (isURL(audio)) {
|
||||||
|
formData.append('url', audio);
|
||||||
|
} else {
|
||||||
|
formData.append('base64', audio);
|
||||||
|
}
|
||||||
|
|
||||||
|
const { data } = await axios.post(process.env.API_AUDIO_CONVERTER, formData, {
|
||||||
|
headers: {
|
||||||
|
...formData.getHeaders(),
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!data.audio) {
|
||||||
|
throw new InternalServerErrorException('Failed to convert audio');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Buffer.from(data.audio, 'base64');
|
||||||
|
} else {
|
||||||
let inputAudioStream: PassThrough;
|
let inputAudioStream: PassThrough;
|
||||||
|
|
||||||
if (isURL(audio)) {
|
if (isURL(audio)) {
|
||||||
@ -2679,6 +2701,7 @@ export class BaileysStartupService extends ChannelStartupService {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) {
|
public async audioWhatsapp(data: SendAudioDto, file?: any, isIntegration = false) {
|
||||||
const mediaData: SendAudioDto = { ...data };
|
const mediaData: SendAudioDto = { ...data };
|
||||||
|
Loading…
Reference in New Issue
Block a user