Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved: is not possible to export any file #89

Open
xhublist opened this issue Oct 15, 2024 · 1 comment
Open

Solved: is not possible to export any file #89

xhublist opened this issue Oct 15, 2024 · 1 comment

Comments

@xhublist
Copy link

Hello, there is some setting to put inside files about the export? Because i have take the files put into my server and work all except the exportation in both file type extensions.

into developer tools i read also this :

wavesurfer.js:5760 The AudioContext was not allowed to start. It must be resumed (or created) after a user gesture on the page. https://goo.gl/7K7WLu
wavesurfer.js:5976 [Deprecation] The ScriptProcessorNode is deprecated. Use AudioWorkletNode instead. (https://bit.ly/audio-worklet)
actions.js:9 [Deprecation] The ScriptProcessorNode is deprecated. Use AudioWorkletNode instead. (https://bit.ly/audio-worklet)



@xhublist
Copy link
Author

i have solved byself function DownloadFile( with_name, format, kbps, selection, stereo, callback ) {
if (wavesurfer && wavesurfer.backend && wavesurfer.backend.buffer){}
else {
return false;
}

		if (format === 'mp3') {
			worker = new Worker('/HERE PUT THE PATH ABSOLUTE/lame.js');
		}
		else {
			worker = new Worker('/HERE PUT THE PATH ABSOLUTE/wav.js');
		}

		var originalBuffer = wavesurfer.backend.buffer;
		var sample_rate = originalBuffer.sampleRate;

		var channels = originalBuffer.numberOfChannels;

		var data_left = originalBuffer.getChannelData ( 0 );
		var data_right = null;
		if (channels === 2)
			data_right = originalBuffer.getChannelData ( 1 );

		if (!stereo && channels === 2)
		{
			if (!wavesurfer.ActiveChannels[0] && wavesurfer.ActiveChannels[1])
			{
				data_left  = originalBuffer.getChannelData ( 1 );
				data_right = null;
				channels   = 1;
			}
		}

		if (stereo && !data_right)
		{
			data_right = data_left;
			channels   = 2;
		}
		else if (!stereo && data_right)
		{
			data_right = null;
			channels   = 1;
		}

		var len = data_left.length, i = 0;
		var offset = 0;

		if (selection)
		{
			offset = (selection[0] * sample_rate) >> 0;
			len = ((selection[1] * sample_rate) >> 0) - offset;
		}

		var dataAsInt16ArrayLeft = new Int16Array(len);
		var dataAsInt16ArrayRight = null;


		if (data_right)
		{
			dataAsInt16ArrayRight = new Int16Array(len);

			while(i < len) {
				dataAsInt16ArrayLeft[i] = convert(data_left[offset + i]);
			 	dataAsInt16ArrayRight[i] = convert(data_right[offset + i]);
			 	++i;
			}
		}
		else
		{
			while(i < len) {
				dataAsInt16ArrayLeft[i] = convert(data_left[offset + i]);
			 	++i;
			}
		}
		function convert ( n ) {
			 var v = n < 0 ? n * 32768 : n * 32767;       // convert in range [-32768, 32767]
			 return Math.max(-32768, Math.min(32768, v)); // clamp
		}

		worker.onmessage = function( ev ) {
			if (ev.data.percentage)
			{
				callback && callback ( ev.data.percentage );
				return ;
			}
			forceDownload( ev.data );

			worker.terminate ();
			worker = null;
		}

		worker.postMessage ({
			sample_rate: sample_rate,
			kbps:!kbps ? 128 : kbps,
			channels: channels
		});
		worker.postMessage ( dataAsInt16ArrayLeft.buffer, [dataAsInt16ArrayLeft.buffer] );
		if (data_right)
			worker.postMessage ( dataAsInt16ArrayRight.buffer, [dataAsInt16ArrayRight.buffer] );
		else
			worker.postMessage (null);

		// function forceDownload ( mp3Data ) {
		// 	var blob = new Blob (mp3Data, {type:'audio/mp3'});
		function forceDownload ( blob ) {			
			var url = (window.URL || window.webkitURL).createObjectURL(blob);

			var a = document.createElement( 'a' );
			a.href = url;
			a.download = with_name ? with_name : 'output.mp3';
			a.style.display = 'none';
			document.body.appendChild( a );
			a.click();

			callback && callback ('done');
		}
	}

the problem is in actions.js in this function and in details here : if (format === 'mp3') {
worker = new Worker('/HERE PUT THE PATH ABSOLUTE/lame.js');
}
else {
worker = new Worker('/HERE PUT THE PATH ABSOLUTE/wav.js');
}

@xhublist xhublist changed the title is not possible to export any file Solved: is not possible to export any file Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant