mickzer
mickzer

Reputation: 6338

Web Audio - Change pitch of live microphone

I have this code to make a live connection between my microphone and my speakers. Is it possible to change the pitch of my voice in real time?

navigator.getUserMedia(
  { audio: true },
  function(stream) {
    window.AudioContext = window.AudioContext || window.webkitAudioContext;
     var ctx= new AudioContext();

     // Create an AudioNode from the stream.
     var mediaStreamSource = ctx.createMediaStreamSource( stream );

     // Connect it to the destination to hear yourself (or any other node for processing!)
     mediaStreamSource.connect( ctx.destination );

  },
  function(err) {
    console.log(err);
  }
);

Upvotes: 2

Views: 2478

Answers (2)

cwilso
cwilso

Reputation: 13908

Actually, this is possible. I did it in the Input Effects demo (https://webaudiodemos.appspot.com/input/index.html, select "Pitch Shifter") using a granular resynthesis approach, using a pair of delay nodes with looping ramping delayTimes. If you wanted to do something fancier (like, phase shift vocoding), you'd probably need a ScriptProcessor/AudioWorker.

Upvotes: 4

Raymond Toy
Raymond Toy

Reputation: 6048

I don't think there's any way in WebAudio to do a pitch shift unless you implement it yourself in a ScriptProcessorNode or the upcoming AudioWorkerNode.

Upvotes: 0

Related Questions