# Export sketch as audio?

**URL:** <https://discourse.processing.org/t/export-sketch-as-audio/30111>\
**Category:** Libraries\
**Created:** [May 15, 2021, 7:07pm UTC](https://discourse.processing.org/t/export-sketch-as-audio/30111 "2021-05-15T19:07:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![TheZipCreator](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/thezipcreator/32/15979_2.png) [@TheZipCreator](https://discourse.processing.org/u/TheZipCreator)\
**Post date:** [May 15, 2021, 7:07pm UTC](https://discourse.processing.org/t/export-sketch-as-audio/30111/1 "2021-05-15T19:07:37Z")

</div>

so I made the following sketch to scramble audio, and I’m wondering how to export the audio I get from it. Currently I’m just using audacity to record desktop audio while the sketch is running, but that takes long as I must record for however long I want the scrambled output to be. How do I export sketches as audio so I don’t have to do this?

```auto
import processing.sound.*;
//SETTINGS
int minSegLength = 5; //Minimum length of segments (in 10ths of a second)
int maxSegLength = 30; //Maximum length of segments (in 10ths of a second)
//NOT SETTINGS
SoundFile source; //File to scramble
int curSegLength; //Length of current segment (in 10ths of a second)
int segTime; //Time when the current segment started playing
void setup() {
  source = new SoundFile(this, "source.mp3");
  segTime = getTimeIn10thsOfSecond();
  curSegLength = floor(random(minSegLength, maxSegLength));
  source.loop();
}
void draw() {
  if(getTimeIn10thsOfSecond() > segTime+curSegLength) { 
    //Start new segment
    curSegLength = floor(random(minSegLength, maxSegLength));
    segTime = getTimeIn10thsOfSecond();
    source.jump(random(source.duration()));
  }
}

int getTimeIn10thsOfSecond() {
  return (millis()/100)+(second()*10)+(minute()*60*10)+(hour()*60*60*10)+(day()*60*60*24*10);
}

```

---

<div class="post-metadata">

**Author:** ![josephh](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/josephh/32/210_2.png) [@josephh](https://discourse.processing.org/u/josephh)\
**Post date:** [May 15, 2021, 10:52pm UTC](https://discourse.processing.org/t/export-sketch-as-audio/30111/2 "2021-05-15T22:52:16Z")

</div>

Hi,

Maybe this can help 😉 :

> [@Saving AudioSample as a sound file of any format](https://discourse.processing.org/t/saving-audiosample-as-a-sound-file-of-any-format/23174):
>
> please format code with \</\> button \* [homework policy](https://discourse.processing.org/faq/#homework) \* [asking questions](https://discourse.processing.org/t/2147) Hello, I am using the sound library to generate sound from existing .wav files. And after looking for a while for a way to save the generated sound to a file, I haven’t found any (simple) solution. It just surprises me that a library such as .sound that enables you to open and manipuate sound files so easily, does not include a save or export function. Am I missing something here? Is it that hard to create sound files? …

> **[Processing 2.x and 3.x Forum](https://forum.processing.org/two/discussion/4339/how-to-save-a-wav-file-using-audiosystem-and-audioinputstream-of-javasound)**
>
> Processing is an electronic sketchbook, a language and a worldwide community. This is its forum.
