bump
This commit is contained in:
@@ -4,7 +4,12 @@ package com.birdsounds.identify
|
||||
import android.util.Log
|
||||
import com.google.android.gms.wearable.MessageEvent
|
||||
import com.google.android.gms.wearable.WearableListenerService
|
||||
import com.theeasiestway.opus.Constants
|
||||
import com.theeasiestway.opus.Opus
|
||||
import decodeAACToPCM
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.nio.ByteBuffer
|
||||
import java.nio.ByteOrder
|
||||
|
||||
class MessageListenerService : WearableListenerService() {
|
||||
|
||||
@@ -12,7 +17,8 @@ class MessageListenerService : WearableListenerService() {
|
||||
// fun placeSoundClassifier(soundClassifier: SoundClassifier)
|
||||
override fun onMessageReceived(p0: MessageEvent) {
|
||||
super.onMessageReceived(p0)
|
||||
|
||||
val codec_opus = Opus()
|
||||
codec_opus.decoderInit(Constants.SampleRate._48000(), Constants.Channels.mono())
|
||||
// MainActivity
|
||||
Log.w(TAG, "Data recv: "+p0.data.size.toString() + " bytes")
|
||||
val soundclassifier = MainActivity.soundClassifier
|
||||
@@ -24,31 +30,49 @@ class MessageListenerService : WearableListenerService() {
|
||||
}
|
||||
|
||||
var tstamp_bytes = p0.data.copyOfRange(0, Long.SIZE_BYTES)
|
||||
var audio_bytes = p0.data.copyOfRange(Long.SIZE_BYTES, p0.data.size)
|
||||
var audio_bytes_og = p0.data.copyOfRange(Long.SIZE_BYTES, p0.data.size)
|
||||
|
||||
var string_send: String = ""
|
||||
val pcm_byte_array = decodeAACToPCM(audio_bytes)
|
||||
|
||||
Log.e(TAG,"Size of short array buffer: "+ pcm_byte_array.size.toString());
|
||||
// ByteBuffer.wrap(audio_bytes).order(
|
||||
// ByteOrder.LITTLE_ENDIAN
|
||||
// ).asShortBuffer().get(short_array)
|
||||
Log.e(TAG, pcm_byte_array.sum().toString())
|
||||
val buffer = ByteBuffer.wrap(audio_bytes_og)
|
||||
val sound_a = ByteArrayOutputStream();
|
||||
val byteArrayList = mutableListOf<ByteArray>()
|
||||
while (buffer.hasRemaining())
|
||||
{
|
||||
val num_to_read = buffer.get().toInt()
|
||||
val read_this = ByteArray(num_to_read)
|
||||
buffer.get(read_this)
|
||||
val decoded = codec_opus.decode(read_this, Constants.FrameSize._120())
|
||||
sound_a.write(decoded);
|
||||
// Log.e(TAG,"Decompressed ${read_this.size} to ${decoded?.size}")
|
||||
}
|
||||
val audio_bytes = sound_a.toByteArray()
|
||||
|
||||
codec_opus.decoderRelease();
|
||||
|
||||
val short_array = ShortArray(audio_bytes.size/2)
|
||||
// Log.e(TAG,"Size of short array buffer: "+ decoded?.size.toString());
|
||||
|
||||
ByteBuffer.wrap(audio_bytes).order(
|
||||
ByteOrder.LITTLE_ENDIAN
|
||||
).asShortBuffer().get(short_array)
|
||||
// Log.e(TAG, pcm_byte_array.sum().toString())
|
||||
Log.e(TAG, "STARTING SCORING");
|
||||
|
||||
// var sorted_list = soundclassifier.executeScoring(short_array)
|
||||
// Log.w(TAG, "FINISHED SCORING");
|
||||
// Log.w(TAG, "")
|
||||
// for (i in 0 until 5) {
|
||||
// val score = sorted_list[i].value
|
||||
// val index = sorted_list[i].index
|
||||
// val species_name = soundclassifier.labelList[index]
|
||||
// Log.w(TAG, species_name + ", " + score.toString())
|
||||
// string_send+= species_name
|
||||
// string_send+=','
|
||||
// string_send+=score.toString()
|
||||
// string_send+=';'
|
||||
// }
|
||||
|
||||
var string_send: String = ""
|
||||
var sorted_list = soundclassifier.executeScoring(short_array)
|
||||
Log.w(TAG, "FINISHED SCORING");
|
||||
Log.w(TAG, "")
|
||||
for (i in 0 until 5) {
|
||||
val score = sorted_list[i].value
|
||||
val index = sorted_list[i].index
|
||||
val species_name = soundclassifier.labelList[index]
|
||||
Log.w(TAG, species_name + ", " + score.toString())
|
||||
string_send+= species_name
|
||||
string_send+=','
|
||||
string_send+=score.toString()
|
||||
string_send+=';'
|
||||
}
|
||||
MessageSenderFromPhone.sendMessage("/audio", tstamp_bytes + string_send.toByteArray(), this)
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user