首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >录制/创建音频文件前的minim

录制/创建音频文件前的minim
EN

Stack Overflow用户
提问于 2013-07-15 02:38:31
回答 2查看 3K关注 0票数 1

我正在尝试创建一个应用程序,将允许用户一些声音,然后在一个播放的方式使用它。

我想让我的应用程序播放用户将录制的.wav文件。

我很难弄清楚如何对此进行编码,因为我不断收到错误。

代码语言:javascript
复制
    ==== JavaSound Minim Error ====
    ==== Error invoking createInput on the file loader object: null

代码片段:

代码语言:javascript
复制
   import ddf.minim.*;

   AudioInput in;
   AudioRecorder recorder;

   RadioButtons r;
   boolean showGUI = false;
   color bgCol = color(0);

   Minim minim;

   //Recording players
   AudioPlayer player1; 
   AudioPlayer player2;

   void newFile()
   {
      countname =(name+1);
      recorder = minim.createRecorder(in, "data/" + countname + ".wav", true);
   }
   ......

   void setup(){

       minim = new Minim(this);
       in = minim.getLineIn(Minim.MONO, 2048);
       newFile();
       player1 = minim.loadFile("data/" + countname + ".wav");// recording #1
       player2 = minim.loadFile("data/" + countname + ".wav");//recording #2


   void draw() {
   // Draw the image to the screen at coordinate (0,0)
       image(img,0,0);

       //recording button
       if(r.get() == 0)
       {
            for(int i = 0; i < in.left.size()-1; i++)
       }

            if ( recorder.isRecording() )
        {
            text("Currently recording...", 5, 15);
             }
            else
        {
            text("Not recording.", 5, 15);
          }
         }
     //play button
     if(r.get() == 1)
     {
     if(mousePressed){
     .......
     player_1.cue(0);
     player_1.play();
     }
     if(mousePressed){
     .......
     player_2.cue(0);
     player_2.play();
     }
     } 

我有问题的地方在这里:

代码语言:javascript
复制
       player1 = minim.loadFile("data/" + countname + ".wav");// recording #1
       player2 = minim.loadFile("data/" + countname + ".wav");//recording #2

将记录的文件将是1.wav、2.wav。但是我不能把这个放在

代码语言:javascript
复制
       player1.minim.loadFile ("1.wav");
       player2.mminim.loadFile("2.wav");

我该怎么做呢?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-07-24 19:56:59

如AudioRecorder 1的JavaDoc页面所示,需要调用beginRecord()、endRecord()和save(),以便实际记录您想要记录的内容,然后将其保存到磁盘。只要不发生这种情况,就不需要加载loadFile(),因此您将收到错误。所以问题出在你的程序流程中。只有当你的程序达到一个文件已经被记录和保存的状态时,你才能真正加载它。

可能还有一些方法可以让你在录音到达你的音频输入缓冲区时立即回放(通常指的是‘监听’),但据我所知,这并不是你想要的。

抛开这个一般性的概念缺陷不谈,你的代码中似乎还有其他问题,例如countname没有在两个后续的loadFile调用之间迭代(我假设它应该被迭代);而且在某些时候你会有"player_1.play();“(请注意下划线),尽管你可能引用了这个写得不同的变量,在前面用"player1 = minim.loadFile( ... )”初始化?

1

票数 2
EN

Stack Overflow用户

发布于 2018-06-03 07:53:50

这是将音频文件录制到AudioRecorder对象中的方法。加载一个文件,播放它,然后选择要保存到另一个文件中的部分,您可以使用AudioPlayer对象或操作系统提供的您最喜欢的声音播放器来播放该文件。

相关内容

我很难弄清楚如何编码,因为我一直得到一个错误。

尽管它说这是一个错误,但它不会影响你的程序的执行。我会认为这是一个警告,并忽略它。如果你想修复它,我相信你需要编辑文件的标签来正确地设置它们的值。

说明:在代码中,定义你要播放的文件。运行草图时,按r键开始录制,再次按r键停止录制。不要忘记按s键将文件保存为音频文件,该文件将位于data文件夹中。

注意:如果你需要播放wav文件,你需要一个采样器对象,而不是一个FilePlayer对象。

代码语言:javascript
复制
//REFERENCE: https:// forum.processing.org/one/topic/how-can-i-detect-sound-with-my-mic-in-my-computer.html
//REFERENCE: https:// forum.processing.org/two/discussion/21842/is-it-possible-to-perform-fft-with-fileplayer-object-minim

/**
 * This sketch demonstrates how to use an <code>AudioRecorder</code> to record audio to disk. 
 * Press 'r' to toggle recording on and off and the press 's' to save to disk. 
 * The recorded file will be placed in the sketch folder of the sketch.
 * <p>
 * For more information about Minim and additional features, 
 * visit <a href="<a href="http://code.compartmental.net/minim/" target="_blank" rel="nofollow">http://code.compartmental.net/minim/</a>" target="_blank" rel="nofollow"><a href="http://code.compartmental.net/minim/</a>" target="_blank" rel="nofollow">http://code.compartmental.net/minim/</a></a>;
 */

import ddf.minim.*;
import ddf.minim.ugens.*;
import ddf.minim.analysis.*;

Minim         minim;
FilePlayer player;
AudioOutput out;
AudioRecorder recorder;

void setup()
{
  size(512, 200, P3D);
  textFont(createFont("Arial", 12));

  minim = new Minim(this);  
  player = new FilePlayer(minim.loadFileStream("energeticDJ.mp3"));
  // IT DOESN'T WORK FOR WAV files  ====> player = new FilePlayer(minim.loadFileStream("fair1939.wav"));
  out = minim.getLineOut();
  TickRate rateControl = new TickRate(1.f);
  player.patch(rateControl).patch(out);
  recorder = minim.createRecorder(out, dataPath("myrecording.wav"),true);

  player.loop(0);

}

void draw()
{
  background(0); 
  stroke(255);

  // draw a line to show where in the song playback is currently located
  float posx = map(player.position(), 0, player.length(), 0, width);
  stroke(0, 200, 0);
  line(posx, 0, posx, height);



  if ( recorder.isRecording() )
  {
    text("Currently recording...", 5, 15);
  } else
  {
    text("Not recording.", 5, 15);
  }
}

void keyReleased()
{
  if ( key == 'r' ) 
  {
    // to indicate that you want to start or stop capturing audio data, you must call
    // beginRecord() and endRecord() on the AudioRecorder object. You can start and stop
    // as many times as you like, the audio data will be appended to the end of the buffer 
    // (in the case of buffered recording) or to the end of the file (in the case of streamed recording). 
    if ( recorder.isRecording() ) 
    {
      recorder.endRecord();
    } else
    {
      recorder.beginRecord();
    }
  }
  if ( key == 's' )
  {
    // we've filled the file out buffer, 
    // now write it to the file we specified in createRecorder
    // in the case of buffered recording, if the buffer is large, 
    // this will appear to freeze the sketch for sometime
    // in the case of streamed recording, 
    // it will not freeze as the data is already in the file and all that is being done
    // is closing the file.
    // the method returns the recorded audio as an AudioRecording, 
    // see the example  AudioRecorder >> RecordAndPlayback for more about that
    recorder.save();
    println("Done saving.");
  }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17642440

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档