from scipy.io.wavfile import write from infer import vc_single import numpy as np def generate_wav(audio_file='voice.mp3', method='pm', index_rate=0.6, output_file='output.wav', model_path='weights/kanye.pth'): song_output = vc_single( 0, audio_file, 0.0, '', method, '', '', index_rate, model_path, ) if not song_output: return {'error': 'Failed to generate audio. No song output.'} output_status = song_output[0] if output_status != 'Success': return {'error': 'Failed to generate audio. No success message.'} output_bitrate_and_song = song_output[1] if len(output_bitrate_and_song) != 2: return {'error': 'Failed to generate audio. Bitrate and song does not have 2 elements.'} output_bitrate, output_song = output_bitrate_and_song if type(output_bitrate) != int: return {'error': 'Failed to generate audio. Bitrate is not an integer.'} if type(output_song) != np.ndarray: return {'error': 'Failed to generate audio. Song is not a numpy array.'} write(output_file, output_bitrate, output_song) return {'success': 'Audio generated successfully.'}