use of org.eclipse.smarthome.core.audio.AudioException in project smarthome by eclipse.
the class AudioServlet method doGet.
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
removeTimedOutStreams();
final String streamId = StringUtils.substringBefore(StringUtils.substringAfterLast(req.getRequestURI(), "/"), ".");
try (final InputStream stream = prepareInputStream(streamId, resp)) {
if (stream == null) {
logger.debug("Received request for invalid stream id at {}", req.getRequestURI());
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
} else {
IOUtils.copy(stream, resp.getOutputStream());
resp.flushBuffer();
}
} catch (final AudioException ex) {
resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
}
}
use of org.eclipse.smarthome.core.audio.AudioException in project smarthome by eclipse.
the class MacTTSAudioStream method createInputStream.
private InputStream createInputStream() throws AudioException {
String outputFile = generateOutputFilename();
String command = getCommand(outputFile);
try {
Process process = Runtime.getRuntime().exec(command);
process.waitFor();
file = new File(outputFile);
this.length = file.length();
return getFileInputStream(file);
} catch (IOException e) {
throw new AudioException("Error while executing '" + command + "'", e);
} catch (InterruptedException e) {
throw new AudioException("The '" + command + "' has been interrupted", e);
}
}
use of org.eclipse.smarthome.core.audio.AudioException in project smarthome by eclipse.
the class MacTTSAudioStream method generateOutputFilename.
/**
* Generates a unique, absolute output filename
*
* @return Unique, absolute output filename
*/
private String generateOutputFilename() throws AudioException {
File tempFile;
try {
tempFile = File.createTempFile(Integer.toString(text.hashCode()), ".wav");
tempFile.deleteOnExit();
} catch (IOException e) {
throw new AudioException("Unable to create temp file.", e);
}
return tempFile.getAbsolutePath();
}
use of org.eclipse.smarthome.core.audio.AudioException in project smarthome by eclipse.
the class JavaSoundAudioSource method initMicrophone.
private void initMicrophone(javax.sound.sampled.AudioFormat format) throws AudioException {
try {
TargetDataLine microphone;
microphone = AudioSystem.getTargetDataLine(format);
DataLine.Info info = new DataLine.Info(TargetDataLine.class, format);
microphone = (TargetDataLine) AudioSystem.getLine(info);
microphone.open(format);
this.microphone = microphone;
} catch (Exception e) {
throw new AudioException("Error creating the audio input stream.", e);
}
}
Aggregations