如何保存使用TTSLIB的处理草图生成的音频



我正在处理一个处理草图,该草图正在使用rita和ttslib库来生成语音(RITA用于生成马尔可夫文本链,而TTSlib将文本转换为语音(。/p>

我似乎无法弄清楚该怎么做的就是将语音保存为我的PC的音频文件。这是我当前的代码:

import ddf.minim.*;
import rita.*;
import guru.ttslib.*;
Minim minim;
AudioOutput out;
AudioRecorder recorder;
TTS voice1, voice2, voice3;
RiMarkov rm;
String[] sourceTextArray, script;
String title, sourceText;
int targetScriptLength;
void setup() {
  noLoop();
  minim = new Minim(this);
  out = minim.getLineOut();
  recorder = minim.createRecorder(out, "recording.wav");
    System.setProperty("mbrola.base","C:\Users\kandr\Desktop\Dropbox\Coding & Web Design\Processing 3\libraries\mbrola\");
}
void draw() {
  generateScript("https://en.wikipedia.org/wiki/Special:Random");
  prepareVoices();
  recorder.beginRecord();
  speakScript(script);
  recorder.endRecord();
  recorder.save();
}

void prepareVoices() {
  voice1 = new TTS("mbrola_us1");
  voice1.setPitch(180.0);
  voice1.setPitchRange(25.0);
  voice2 = new TTS("mbrola_us3");
  voice2.setPitch(120.0);
  voice2.setPitchRange(15.0);
  voice3 = new TTS("mbrola_us3");
  voice3.setPitch(0.0);
}

void generateScript(String sourceURL) {
  sourceTextArray = loadStrings(sourceURL);
  sourceText = join(sourceTextArray, " ");
  // find random article's title
  title = sourceText.substring(sourceText.indexOf("<h1 id="firstHeading" class="firstHeading" lang="en">") + 53, sourceText.indexOf("</h1>"));
  title = title.replaceAll("<.*?>", "");
  // load the source text into our Markov generator
  rm = new RiMarkov(3);
  rm.loadText(sourceText);
  // set the target script size and instantiate an array to hold the lines
  targetScriptLength = 20;
  script = new String[targetScriptLength];
  // generate lines to populate the script 
  for (int l = 0; l < targetScriptLength; l++) {
    script[l] = rm.generateSentence();
  }
}

void speakScript(String[] scriptArr) {
  for (int s = 0; s < scriptArr.length; s+=2) {
    voice1.speak(scriptArr[s]);
    voice2.speak(scriptArr[s+1]);
  } 
}

如您所见,我尝试使用最小库的AudioreCorder类来记录我的草图输出的音频。但是,没有记录实际的音频 - 我最终拿出一个空的WAV文件。我还尝试将AudioreCorder对象设置为可记录的源作为音频输入,但这只是记录了我笔记本电脑的麦克风的声音。

我还查看了处理带随附的声音库,但没有看到合适的课程用于录制音频。

任何人都可以向我指出正确的方向,以弄清楚如何获取我的草图来记录它通过ttslib生成的音频?

首先,即使您编辑了问题,您发布的代码仍然需要其他文件,因此不能进行测试。

无论如何,问题似乎在于最小的API,因此需要从草图外部完成音频路由。因为您在Windows上工作,所以将录制设备更容易变为"立体声混合"。这将将系统的音频输出重新安装到输入中,因此可通过最小值记录。

以下是我使用ttslib示例和最小录音机示例改编的一个小草图,该示例记录了TTSLIB库产生的语音。如果音频从系统设置重新路由。

import ddf.minim.*;
import ddf.minim.ugens.*;
import guru.ttslib.*;
Minim minim;
TTS tts;
AudioInput in;
AudioRecorder recorder;
boolean recorded;
AudioOutput out;
FilePlayer player;
void setup()
{
  size(512, 200, P3D);
  tts = new TTS();
  minim = new Minim(this);
  in = minim.getLineIn();
  recorder = minim.createRecorder(in, "test.wav", true);
  out = minim.getLineOut( Minim.STEREO );
  textFont(createFont("Arial", 12));
}
void draw()
{
  background(0); 
  stroke(255);
  for(int i = 0; i < in.left.size()-1; i++)
  {
    line(i, 50 + in.left.get(i)*50, i+1, 50 + in.left.get(i+1)*50);
    line(i, 150 + in.right.get(i)*50, i+1, 150 + in.right.get(i+1)*50);
  }
  if ( recorder.isRecording() )
  {
    text("Now recording, press the r key to stop recording.", 5, 15);
  }
  else if ( !recorded )
  {
    text("Press the r key to start recording.", 5, 15);
  }
  else
  {
    text("Press the s key to save the recording to disk and play it back in the sketch.", 5, 15);
  }
}
void keyReleased()
{
  if ( !recorded && key == 'r' ) 
  {
    if ( recorder.isRecording() ) 
    {
      recorder.endRecord();
      recorded = true;
    }
    else 
    {
      recorder.beginRecord();
    }
  }
  if ( recorded && key == 's' )
  {
    if ( player != null )
    {
        player.unpatch( out );
        player.close();
    }
    player = new FilePlayer( recorder.save() );
    player.patch( out );
    player.play();
  }
}
void mousePressed() {
  tts.speak("Hi! This voice is being recorded");
}

相关内容

  • 没有找到相关文章

最新更新