Skip to content

Commit

Permalink
New message (#42)
Browse files Browse the repository at this point in the history
* Adding new audio_info message. Temporary fix for downstream components that need important information from the stream that cannot split the preproc_audio stream

* Update raspberry java dependencies
  • Loading branch information
Andrew Tabarez authored Jun 24, 2020
1 parent 1b0b426 commit b06510d
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 5 deletions.
8 changes: 4 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,12 @@ matrix:
- wget -q http://archive.raspberrypi.org/debian/pool/main/a/alsa-lib/libasound2-dev_1.1.3-5+rpi3_armhf.deb
- ar x libasound2-dev_1.1.3-5+rpi3_armhf.deb
- tar xf data.tar.xz -C $HOME/alsa
- wget -q http://raspbian.mirror.constant.com/raspbian/pool/main/o/openjdk-8/openjdk-8-jdk_8u242-b08-1~deb9u1_armhf.deb
- ar x openjdk-8-jdk_8u242-b08-1~deb9u1_armhf.deb
- wget -q http://raspbian.mirror.constant.com/raspbian/pool/main/o/openjdk-8/openjdk-8-jdk_8u252-b09-1~deb9u1_armhf.deb
- ar x openjdk-8-jdk_8u252-b09-1~deb9u1_armhf.deb
- mkdir $HOME/jdk
- tar xf data.tar.xz -C $HOME/jdk
- wget -q http://raspbian.mirror.constant.com/raspbian/pool/main/o/openjdk-8/openjdk-8-jre-headless_8u242-b08-1~deb9u1_armhf.deb
- ar x openjdk-8-jre-headless_8u242-b08-1~deb9u1_armhf.deb
- wget -q http://raspbian.mirror.constant.com/raspbian/pool/main/o/openjdk-8/openjdk-8-jre-headless_8u252-b09-1~deb9u1_armhf.deb
- ar x openjdk-8-jre-headless_8u252-b09-1~deb9u1_armhf.deb
- mkdir $HOME/jre
- tar xf data.tar.xz -C $HOME/jre
- mkdir $HOME/pydev
Expand Down
1 change: 1 addition & 0 deletions src/ChannelMessenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ std::string LoopProcessor::QuietGodec = "quiet_godec";
std::string LoopProcessor::SlotTimeMap = "time_map";
std::string LoopProcessor::SlotControl = "control";
std::string LoopProcessor::SlotSearchOutput = "fst_search_output";
std::string LoopProcessor::SlotAudioInfo = "audio_info";

std::string DecoderMessage::describeThyself() const {
std::stringstream ss;
Expand Down
5 changes: 5 additions & 0 deletions src/core_components/AudioPreProcessor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@ AudioPreProcessorComponent::AudioPreProcessorComponent(std::string id, Component
ss << SlotStreamedAudio << "_" << channelIdx;
requiredOutputSlots.push_back(ss.str());
}
requiredOutputSlots.push_back(SlotAudioInfo);
initOutputs(requiredOutputSlots);
}

Expand Down Expand Up @@ -297,6 +298,10 @@ void AudioPreProcessorComponent::ProcessMessage(const DecoderMessageBlock& msgBl
pushToOutputs(ss.str(), outMsg);
}

DecoderMessage_ptr audioInfoMsg = AudioInfoDecoderMessage::create(outTimestamp, mTargetSamplingRate, outputTimePerSample);
(boost::const_pointer_cast<DecoderMessage>(audioInfoMsg))->setFullDescriptorString(audioBaseMsg->getFullDescriptorString());
pushToOutputs(SlotAudioInfo, audioInfoMsg);

// End of utterance? Reset everything
if (convStateMsg->mLastChunkInUtt) {
mUttStartStreamOffset = outTimestamp;
Expand Down
75 changes: 75 additions & 0 deletions src/core_components/GodecMessages.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ uuid UUID_NbestDecoderMessage = godec_uuid_gen("e01bbc32-73ad-40d9-9ad6-ce491a5b
uuid UUID_TimeMapDecoderMessage = godec_uuid_gen("c335ce22-97ae-4b07-b952-6c509e27e6c3");
uuid UUID_BinaryDecoderMessage = godec_uuid_gen("e754362e-58da-4488-831e-9277f8be1d66");
uuid UUID_JsonDecoderMessage = godec_uuid_gen("ebe880c8-f6d9-4b7d-8d15-7589302b6946");
uuid UUID_AudioInfoDecoderMessage = godec_uuid_gen("b1464c2d-8d1e-4e75-bb4e-83632b1201d0");

ProcessingMode StringToProcessMode(std::string s) {
if (s == "LowLatency") return LowLatency;
Expand Down Expand Up @@ -777,6 +778,80 @@ DecoderMessage_ptr NbestDecoderMessage::fromPython(PyObject* pMsg) {
}
#endif

/*
############ Audio Info decoder message ###################
*/

std::string AudioInfoDecoderMessage::describeThyself() const {
std::stringstream ss;
ss << DecoderMessage::describeThyself();
ss << "Audio Information, sample rate=" << mSampleRate << ", ticks per sample=" << mTicksPerSample << std::endl;
return ss.str();
}

DecoderMessage_ptr AudioInfoDecoderMessage::create(uint64_t time, float sampleRate, float ticksPerSample) {
AudioInfoDecoderMessage* msg = new AudioInfoDecoderMessage();
msg->setTime(time);
msg->mSampleRate = sampleRate;
msg->mTicksPerSample = ticksPerSample;
return DecoderMessage_ptr(msg);
}

DecoderMessage_ptr AudioInfoDecoderMessage::clone() const { return DecoderMessage_ptr(new AudioInfoDecoderMessage(*this)); }

bool AudioInfoDecoderMessage::mergeWith(DecoderMessage_ptr msg, DecoderMessage_ptr &remainingMsg, bool verbose) {
auto mergeMsg = boost::static_pointer_cast<const AudioInfoDecoderMessage>(msg);
if ((mSampleRate != mergeMsg->mSampleRate) && (mTicksPerSample == mergeMsg->mTicksPerSample)) GODEC_ERR << "sample_rate or ticks_per_sample has changed.\n Current message : " << describeThyself() << "\n, to be merged: " << mergeMsg->describeThyself();
setTime(mergeMsg->getTime());
mSampleRate = mergeMsg->mSampleRate;
mTicksPerSample = mergeMsg->mTicksPerSample;
return false;
}

bool AudioInfoDecoderMessage::canSliceAt(uint64_t sliceTime, std::vector<DecoderMessage_ptr>& msgList, uint64_t streamStartOffset, bool verbose) {
// Convo state can always be sliced
return true;
}
bool AudioInfoDecoderMessage::sliceOut(uint64_t sliceTime, DecoderMessage_ptr& sliceMsg, std::vector<DecoderMessage_ptr>& msgList, int64_t streamStartOffset, bool verbose) {
auto firstMsg = boost::static_pointer_cast<const AudioInfoDecoderMessage>(msgList[0]);
if (firstMsg->getTime() == sliceTime) {
sliceMsg = msgList[0];
msgList.erase(msgList.begin());
return true;
} else {
sliceMsg = AudioInfoDecoderMessage::create(sliceTime,
firstMsg->mSampleRate, firstMsg->mTicksPerSample);
return true;
}
}

void AudioInfoDecoderMessage::shiftInTime(int64_t deltaT) {
setTime((int64_t)getTime()+deltaT);
}

jobject AudioInfoDecoderMessage::toJNI(JNIEnv* env) {
GODEC_ERR << "AudioInfoDecoderMessage::toJNI not implemented yet!";
return NULL;
};

DecoderMessage_ptr AudioInfoDecoderMessage::fromJNI(JNIEnv* env, jobject jMsg) {
GODEC_ERR << "AudioInfoDecoderMessage::fromJNI not implemented yet!";
return NULL;
}

#ifndef ANDROID
PyObject* AudioInfoDecoderMessage::toPython() {
GODEC_ERR << "AudioInfoDecoderMessage::toPython not implemented yet!";
return NULL;
}
DecoderMessage_ptr AudioInfoDecoderMessage::fromPython(PyObject* pMsg) {
GODEC_ERR << "AudioInfoDecoderMessage::fromPython not implemented yet!";
return NULL;

}
#endif


/*
############ Conversation state decoder message ###################
*/
Expand Down
34 changes: 34 additions & 0 deletions src/core_components/GodecMessages.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ extern uuid UUID_NbestDecoderMessage;
extern uuid UUID_TimeMapDecoderMessage;
extern uuid UUID_BinaryDecoderMessage;
extern uuid UUID_JsonDecoderMessage;
extern uuid UUID_AudioInfoDecoderMessage;

enum ProcessingMode {
LowLatency,
Expand Down Expand Up @@ -80,6 +81,39 @@ class AudioDecoderMessage : public DecoderMessage {
}
};

class AudioInfoDecoderMessage : public DecoderMessage {
public:
float mSampleRate;
float mTicksPerSample;

std::string describeThyself() const;
DecoderMessage_ptr clone() const;

static DecoderMessage_ptr create(uint64_t time, float sampleRate, float ticksPerSample);
bool mergeWith(DecoderMessage_ptr msg, DecoderMessage_ptr &remainingMsg, bool verbose);
bool canSliceAt(uint64_t sliceTime, std::vector<DecoderMessage_ptr>& msgList, uint64_t streamStartOffset, bool verbose);
bool sliceOut(uint64_t sliceTime, DecoderMessage_ptr& sliceMsg, std::vector<DecoderMessage_ptr>& msgList, int64_t streamStartOffset, bool verbose);
void shiftInTime(int64_t deltaT);
jobject toJNI(JNIEnv* env);
static DecoderMessage_ptr fromJNI(JNIEnv* env, jobject jMsg);
#ifndef ANDROID
PyObject* toPython();
static DecoderMessage_ptr fromPython(PyObject* pMsg);
#endif

uuid getUUID() const { return UUID_AudioInfoDecoderMessage; }
static uuid getUUIDStatic() { return UUID_AudioInfoDecoderMessage; }

private:
friend class boost::serialization::access;
template<typename Archive>
void serialize(Archive & ar, const unsigned int version) {
ar & boost::serialization::base_object<DecoderMessage>(*this);
ar & mSampleRate;
ar & mTicksPerSample;
}
};

class FeaturesDecoderMessage : public DecoderMessage {
public:
Matrix mFeatures;
Expand Down
1 change: 1 addition & 0 deletions src/include/godec/ChannelMessenger.h
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ class LoopProcessor {
static std::string SlotTimeMap;
static std::string SlotControl;
static std::string SlotSearchOutput;
static std::string SlotAudioInfo;

// Don't use the following
void startDecodingLoop();
Expand Down
3 changes: 2 additions & 1 deletion test/resample_sub.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
},
"outputs":
{
"streamed_audio_0": "preproc_audio"
"streamed_audio_0": "preproc_audio",
"audio_info": "streamed_info"
}
},
"dummy_comp":
Expand Down

0 comments on commit b06510d

Please sign in to comment.