Using Amazon's avs SDK for Alexa to parse Audio files
<p>In general I wanna use the amazon's avs sdk for Alexa to parse audio files and not just microphone recording.</p>

<p>using OSX 10.11.6.</p>

<p>So first I downloaded <code>Alexa Voice Service Sample App</code> from <a href="https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/java-client-sample">https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/java-client-sample</a></p>

<p>Then I configured and executed the companionService (nodejs) and then the java client and it works.. I say stuff on the microphone and Alexa responds. now I want to add a capability to load sound and play it from the computer instead of just the microphone.</p>

<p>So first I created a function to add a button to the UI.
so I edited <code>samples/javaclient/src/main/java/com/amazon/alexa/avs/AVSApp.java</code>. I duplicated the function that adds the "Start Listening" button and modified it:</p>

<pre><code>private void addBrowseField() {
    final RecordingRMSListener rmsListener = this;
    browseButton = new JButton(BROWSE_LABEL);
    browseButton.setEnabled(true);
    browseButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            controller.onUserActivity();
            if (browseButton.getText().equals(BROWSE_LABEL)) { // if in idle mode
                browseButton.setText(BROWSE_STOP_LABEL);
                RequestListener requestListener = new RequestListener() {

                    @Override
                    public void onRequestSuccess() {
                        finishProcessing();
                    }

                    @Override
                    public void onRequestError(Throwable e) {
                        log.error("An error occured creating speech request", e);
                        JOptionPane.showMessageDialog(getContentPane(), e.getMessage(), "Error",
                                JOptionPane.ERROR_MESSAGE);
                        browseButton.doClick();
                        finishProcessing();
                    }
                };

                controller.startFileLoading("/Users/ufk/Desktop/eli3.raw", requestListener);
                // controller.stopRecording(); /// stop the recording so the request can complete
            } else {
                browseButton.setText(BROWSE_LABEL);
                controller.stopRecording();
            }
        }
    });
    getContentPane().add(browseButton);
}
</code></pre>

<p>Then I added the execution of this function in the private AVSApp function:</p>

<pre><code>private AVSApp(DeviceConfig config) throws Exception {
...
        addBrowseField();
...
}
</code></pre>

<p>ok now... in my new <code>addBrowseField()</code> function I'm calling a new function I created in the controller called <code>startFileRecording</code>.
so I modified 
<code>samples/javaclient/src/main/java/com/amazon/alexa/avs/AVSController.java</code></p>

<p>by copying the <code>startRecording</code> function to <code>startFileLoading</code> and modifying it:</p>

<pre><code>public void startFileLoading(String path,RequestListener requestListener) {

    try {
        InputStream in = (InputStream)new BufferedInputStream(new FileInputStream(new File(path)));
        String dialogRequestId = dialogRequestIdAuthority.createNewDialogRequestId();

        RequestBody body = RequestFactory.createSpeechRegonizerRecognizeRequest(dialogRequestId,
                PROFILE, FORMAT, player.getPlaybackState(), player.getSpeechState(),
                alertManager.getState(), player.getVolumeState());

        dependentQueue.clear();

        avsClient.sendEvent(body, in, requestListener, AUDIO_TYPE);

        speechRequestAudioPlayerPauseController.startSpeechRequest();

    } catch (Exception e) {
        player.playMp3FromResource(ERROR_SOUND);
        requestListener.onRequestError(e);
    }
}
</code></pre>

<p>Now as you can see, I use the file <code>eli3.raw</code>. I recorded myself saying a command (only audio) and converted it to LPCM with <code>ffmpeg -i eli.m4a -f s16le -ac 1 -acodec pcm_s16le eli3.raw</code></p>

<p>So I click the newly created <code>Browse</code> button that actually loads the <code>eli3.raw</code> audio file, and a few seconds I click the <code>Stop Browse</code> button and nothing really happens.</p>

<p>I get no java errors, no warning no nothing.</p>

<p>I'm pretty new to the all avs sdk so I'm probably doing something wrong.. just no idea what.</p>