Reputation: 32104
In general I wanna use the amazon's avs sdk for Alexa to parse audio files and not just microphone recording.
using OSX 10.11.6.
So first I downloaded Alexa Voice Service Sample App
from https://developer.amazon.com/public/solutions/alexa/alexa-voice-service/docs/java-client-sample
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.
So first I created a function to add a button to the UI.
so I edited samples/javaclient/src/main/java/com/amazon/alexa/avs/AVSApp.java
. I duplicated the function that adds the "Start Listening" button and modified it:
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);
}
Then I added the execution of this function in the private AVSApp function:
private AVSApp(DeviceConfig config) throws Exception {
...
addBrowseField();
...
}
ok now... in my new addBrowseField()
function I'm calling a new function I created in the controller called startFileRecording
.
so I modified
samples/javaclient/src/main/java/com/amazon/alexa/avs/AVSController.java
by copying the startRecording
function to startFileLoading
and modifying it:
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);
}
}
Now as you can see, I use the file eli3.raw
. I recorded myself saying a command (only audio) and converted it to LPCM with ffmpeg -i eli.m4a -f s16le -ac 1 -acodec pcm_s16le eli3.raw
So I click the newly created Browse
button that actually loads the eli3.raw
audio file, and a few seconds I click the Stop Browse
button and nothing really happens.
I get no java errors, no warning no nothing.
I'm pretty new to the all avs sdk so I'm probably doing something wrong.. just no idea what.
Upvotes: 7
Views: 1336
Reputation: 32104
ok.. so the format of the audio file was wrong. using ffmpeg with these flags: ffmpeg -i eli.m4a -acodec pcm_s16le -ac 1 -ar 16000 eli.wav
resolved the issue.
Upvotes: 1