Erro bem documentado
libswscale 7. 1.100 / 7. 1.100
libswresample 4. 10.100 / 4. 10.100
libpostproc 57. 1.100 / 57. 1.100
Guessed Channel Layout for Input Stream #0.0 : mono
Input #0, wav, from 'C:\meu\comandos voz\command_1701143904.wav':
Duration: 00:00:03.00, bitrate: 256 kb/s
Stream #0:0: Audio: pcm_s16le ([1][0][0][0] / 0x0001), 16000 Hz, 1 channels, s16, 256 kb/s
Option af (set audio filters) cannot be applied to input url C:\meu\comandos voz\command_1701143904.wav -- you are trying to apply an input option to an output file or vice versa. Move this option before the file it belongs to.
Error parsing options for input file C:\meu\comandos voz\command_1701143904.wav.
Error opening input files: Invalid argument
Exception has occurred: OSError
[WinError 6] O identificador é inválido
File "C:\meu\comparar1arquivocomoutrosreorganizado.py", line 779, in db_commands_listbox.bind('', lambda event: on_command_select_for_augmentation(event, conn)) File "C:\meu\comparar1arquivocomoutrosreorganizado.py", line 836, in on_command_select_for_augmentation augmented_file_paths = augment_audio(file_path, transcription, conn) File "C:\meu\comparar1arquivocomoutrosreorganizado.py", line 1011, in augment_audio add_noise_ffmpeg(input_file, new_file_path, effect_params[1]) File "C:\meu\comparar1arquivocomoutrosreorganizado.py", line 936, in add_noise_ffmpeg subprocess.run(command, check=True) subprocess.CalledProcessError: Command '['ffmpeg', '-i', 'C:\meu\comandos voz\command_1701143904.wav', '-af', 'anoisesrc=c0.5:dur=0.1:level=0.1', '-i', 'C:\meu\comandos voz\command_1701143904.wav', '-filter_complex', 'amix=inputs=2:duration=longest', 'C:\meu\comandos voz\command_1701143904_ruido.wav']' returned non-zero exit status 1.
Escreve os registros provenientes das funções add_noise_ffmpeg e change_pitch_ffmpeg na base de dados corretamente exceto se for o registro preveniente da função add_noise_ffmpeg O ficheiro respectivo com ruído não consegue ser criado no disco.
def augment_audio(input_file, transcription, conn):
effects = {
'velocidade': ('_velocidade.wav', 1.5), # Aumenta a velocidade
'pitch': ('_pitch.wav', 2), # Aumenta o pitch em 2 semitons
'ruido': ('_ruido.wav', 0.1), # Adicionar ruído branco com nível 0.1
# Adicione aqui outros efeitos conforme desejar
}
augmented_file_paths = []
for effect_name, effect_params in effects.items():
# Construindo o nome do arquivo de saída
new_file_path = input_file.replace('.wav', effect_params[0])
# Aplicando o efeito usando a função específica
if effect_name == 'velocidade':
change_speed_ffmpeg(input_file, new_file_path, effect_params[1])
elif effect_name == 'pitch':
change_pitch_ffmpeg(input_file, new_file_path, effect_params[1])
elif effect_name == 'ruido':
add_noise_ffmpeg(input_file, new_file_path, effect_params[1])
pass
# Processando MFCC e inserindo no banco de dados
new_transcription = f"{transcription}{effect_name}"
new_mfcc = calculate_mfcc(new_file_path)
new_mfcc_blob = sqlite3.Binary(pickle.dumps(new_mfcc, protocol=pickle.HIGHEST_PROTOCOL))
insert_command(conn, new_file_path, new_transcription, new_mfcc_blob)
# Adicionando o caminho do arquivo na lista para uso posterior
augmented_file_paths.append((new_file_path, f"{transcription}{effect_name}"))
return augmented_file_paths
Esta função não funciona.
def add_noise_ffmpeg(input_file, output_file, noise_level):
# Construa o comando ffmpeg para adicionar ruído branco
command = [
'ffmpeg', '-i', input_file, '-af', f'anoisesrc=c0.5:dur=0.1:level={noise_level}',
'-i', input_file, '-filter_complex', 'amix=inputs=2:duration=longest', output_file
]
# Execute o comando
subprocess.run(command, check=True)
Estas duas funções funcionam
def change_speed_ffmpeg(input_file, output_file, speed):
# Construa o comando ffmpeg para mudar a velocidade de reprodução
command = [
'ffmpeg', '-i', input_file, '-filter:a', f'atempo={speed}', output_file
]
# Execute o comando
subprocess.run(command, check=True)
def change_pitch_ffmpeg(input_file, output_file, semitones):
# Construa o comando ffmpeg para mudar o pitch
command = [
'ffmpeg', '-i', input_file,
'-af', f'asetrate=44100*2^({semitones}/12),aresample=44100', output_file
]
# Execute o comando
subprocess.run(command, check=True)
Não consegues arranjar uma função que funcione com noise?