Search in sources :

Example 1 with AudioException

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());
    }
}
Also used : InputStream(java.io.InputStream) AudioException(org.eclipse.smarthome.core.audio.AudioException)

Example 2 with AudioException

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);
    }
}
Also used : AudioException(org.eclipse.smarthome.core.audio.AudioException) IOException(java.io.IOException) File(java.io.File)

Example 3 with AudioException

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();
}
Also used : AudioException(org.eclipse.smarthome.core.audio.AudioException) IOException(java.io.IOException) File(java.io.File)

Example 4 with AudioException

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);
    }
}
Also used : TargetDataLine(javax.sound.sampled.TargetDataLine) DataLine(javax.sound.sampled.DataLine) AudioException(org.eclipse.smarthome.core.audio.AudioException) AudioException(org.eclipse.smarthome.core.audio.AudioException) TargetDataLine(javax.sound.sampled.TargetDataLine)

Aggregations

AudioException (org.eclipse.smarthome.core.audio.AudioException)4 File (java.io.File)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)1 DataLine (javax.sound.sampled.DataLine)1 TargetDataLine (javax.sound.sampled.TargetDataLine)1