사운드 클라우드 요소가 포함 된 작은 웹 페이지가 있는데 주파수 스펙트럼 분석기를 만들고 싶습니다. 지금까지는 로컬 사운드 파일을 사용하는 데 성공했지만, 임베디드 요소에서 오디오 데이터를 가져 오는 방법을 알 수는 없습니다.임베디드 사운드 클립 요소에서 사운드 데이터 가져 오기
임베디드 요소에서 사운드 데이터를 추출하는 방법이 있습니까?
간단한 작업이 아니라면 가능한 경우 브라우저에서 현재 재생중인 사운드를 분석 할 수 있으면 만족 스럽습니다. 사전에
감사합니다 :)
정말 날에 의해 작성된 코드가 아닌은 (내가
) 튜토리얼에서 대부분 발견 된 HTML (내장 사운드 클라우드 태그)
<iframe id="em1" width="100%" height="450" scrolling="no" frameborder="no" src="https://w.soundcloud.com/player/?url=https%3A//api.soundcloud.com/tracks/144737157&auto_play=false&hide_related=false&visual=true"></iframe>
JS, 나는 어떻게 든 SoundCloudAudioSource를 임베디드 태그 또는 전체 브라우저 윈도우에 첨부하려고합니다.
var SoundCloudAudioSource = function(audioElement) {
var player = document.getElementById(audioElement);
var self = this;
var analyser;
var audioCtx = new (window.AudioContext || window.webkitAudioContext); // this is because it's not been standardised accross browsers yet.
analyser = audioCtx.createAnalyser();
analyser.fftSize = 256; // see - there is that 'fft' thing.
var source = audioCtx.createMediaElementSource(player); // this is where we hook up the <audio> element
source.connect(analyser);
analyser.connect(audioCtx.destination);
var sampleAudioStream = function() {
// This closure is where the magic happens. Because it gets called with setInterval below, it continuously samples the audio data
// and updates the streamData and volume properties. This the SoundCouldAudioSource function can be passed to a visualization routine and
// continue to give real-time data on the audio stream.
analyser.getByteFrequencyData(self.streamData);
// calculate an overall volume value
var total = 0;
for (var i = 0; i < 80; i++) { // get the volume from the first 80 bins, else it gets too loud with treble
total += self.streamData[i];
}
self.volume = total;
};
setInterval(sampleAudioStream, 20); //
// public properties and methods
this.volume = 0;
this.streamData = new Uint8Array(128); // This just means we will have 128 "bins" (always half the analyzer.fftsize value), each containing a number between 0 and 255.
this.playStream = function(streamUrl) {
// get the input stream from the audio element
player.setAttribute('src', streamUrl);
player.play();
}
}};
일부 코드를 공유합니다. 당신은 위젯이나 scoembed 메서드를 사용합니까? 일반적으로 mp3 데이터는 아마존에게 전달되는 URL 뒤에 있습니다. – devbnz
임베디드 요소에서이 mp3 데이터에 액세스 할 수 있습니까? – user1291510
나는 sc 임베디드 물건에 익숙하지 않지만 이미이 정보가있다. (https://api.soundcloud.com/tracks/144737157) - API를 사용하여 mp3 파일을 얻을 수있다. – devbnz