Anonymous user
Record sound: Difference between revisions
→{{header|Scala}}
(Add Nimrod) |
|||
Line 280:
=={{header|Scala}}==
[[Category:Scala Implementations]]{{libheader|Scala}}<lang Scala>import java.io.{File, IOException}
▲import javax.sound.sampled.{ AudioFileFormat, AudioFormat, AudioInputStream, AudioSystem }
▲import javax.sound.sampled.{ DataLine, LineUnavailableException, TargetDataLine }
object SoundRecorder extends App {
// record duration, in milliseconds
final val RECORD_TIME =
// path of the wav file▼
val wavFile = new File("RecordAudio.wav")▼
▲ // path and format of the wav file
val format = new AudioFormat( /*sampleRate =*/ 16000f,▼
▲ val (wavFile, fileType) = (new File("RecordAudio.wav"), AudioFileFormat.Type.WAVE)
/*sampleSizeInBits =*/ 16,
/*channels =*/ 2,
Line 304 ⟶ 297:
val info = new DataLine.Info(classOf[TargetDataLine], format)
val line: TargetDataLine = AudioSystem.getLine(info).asInstanceOf[TargetDataLine]
/
*/▼
//
new Thread(new Runnable() {
def run() {
Line 318 ⟶ 309:
case ex: InterruptedException => ex.printStackTrace()
}
line.
line.close()
println("Finished")
}
}).start()
//Captures the sound and record into a WAV file
Line 328 ⟶ 321:
// checks if system supports the data line
if (AudioSystem.isLineSupported(info)) {
line.open(format)
line.start() // start capturing
val ais = new AudioInputStream(line)▼
println("Recording started")
} else println("Line not supported")
} catch {
case ex: LineUnavailableException => ex.printStackTrace()
case ioe: IOException
}
}</lang>
|