This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Content layer where will pull our feature maps | |
content_layers = ['block5_conv2'] | |
# Style layer we are interested in | |
style_layers = ['block1_conv1', | |
'block2_conv1', | |
'block3_conv1', | |
'block4_conv1', | |
'block5_conv1' | |
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun initializeIntrpreterForVideoQuality(value: Int) { | |
CONTENT_IMAGE_SIZE = value | |
interpreterPredict = getInterpreter(mContext, STYLE_PREDICT_INT_MODEL, false) | |
interpreterTransform = getInterpreter(mContext, STYLE_TRANSFER_INT_MODEL, false) | |
val index = interpreterTransform.getInputIndex("content_image") | |
interpreterTransform.resizeInput( | |
index, | |
intArrayOf(1, CONTENT_IMAGE_SIZE, CONTENT_IMAGE_SIZE, 3) | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** Process of image */ | |
private fun processImage(bitmap: Bitmap) { | |
// Crop bitmap. | |
val croppedBitmap = cropBitmap(bitmap) | |
// Created scaled version of bitmap for model input. | |
scaledBitmap = Bitmap.createScaledBitmap( | |
croppedBitmap, | |
MODEL_WIDTH, | |
MODEL_HEIGHT, true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Apply style inheritance by changing values with seekbar integers | |
for (i in 0 until contentBottleneck[0][0][0].size) { | |
contentBottleneck[0][0][0][i] = | |
contentBottleneck[0][0][0][i] * contentBlendingRatio | |
} | |
for (i in styleBottleneck[0][0][0].indices) { | |
styleBottleneck[0][0][0][i] = | |
styleBottleneck[0][0][0][i] * (1 - contentBlendingRatio) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val contentArray = | |
ImageUtils.bitmapToByteBuffer( | |
contentImageBitmap, | |
CONTENT_IMAGE_SIZE, | |
CONTENT_IMAGE_SIZE | |
) | |
val inputsForStyleTransfer = if (useGPU) { | |
arrayOf(contentArray, styleBottleneckBlended) | |
} else { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val AUDIO_SOURCE = MediaRecorder.AudioSource.VOICE_RECOGNITION | |
private val SAMPLE_RATE = 16000 | |
private val CHANNEL_MASK = AudioFormat.CHANNEL_IN_MONO | |
private val ENCODING = AudioFormat.ENCODING_PCM_16BIT | |
private val BUFFER_SIZE = AudioRecord.getMinBufferSize(SAMPLE_RATE, CHANNEL_MASK, ENCODING) | |
private val AUDIO_FORMAT = | |
AudioFormat.Builder().setEncoding(ENCODING) | |
.setSampleRate(SAMPLE_RATE) | |
.setChannelMask(CHANNEL_MASK) | |
.build() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Start the recording process. | |
*/ | |
mRecorder = AudioRecord.Builder().setAudioSource(AUDIO_SOURCE) | |
.setAudioFormat(AUDIO_FORMAT) | |
.setBufferSizeInBytes(BUFFER_SIZE) | |
.build() | |
mRecorder?.startRecording() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private val readAudio = Runnable { | |
var readBytes: Int | |
buffer = ShortArray(BUFFER_SIZE) | |
while (mRecording) { | |
readBytes = mRecorder!!.read(buffer, 0, BUFFER_SIZE) | |
//Higher volume of microphone | |
//https://stackoverflow.com/questions/25441166/how-to-adjust-microphone-sensitivity-while-recording-audio-in-android | |
if (readBytes > 0) { | |
for (i in 0 until readBytes) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// load tflite file from assets folder | |
@Throws(IOException::class) | |
private fun loadModelFile(context: Context, modelFile: String): MappedByteBuffer { | |
val fileDescriptor = context.assets.openFd(modelFile) | |
val inputStream = FileInputStream(fileDescriptor.fileDescriptor) | |
val fileChannel = inputStream.channel | |
val startOffset = fileDescriptor.startOffset | |
val declaredLength = fileDescriptor.declaredLength | |
val retFile = fileChannel.map(FileChannel.MapMode.READ_ONLY, startOffset, declaredLength) | |
fileDescriptor.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun execute(floatsInput: FloatArray): ArrayList<String> { | |
predictTime = System.currentTimeMillis() | |
val inputSize = floatsInput.size // ~2 seconds of sound | |
var outputSize = 0 | |
when (inputSize) { | |
// 16.000 * 2 seconds recording | |
32000 -> outputSize = ceil(inputSize / 512.0).toInt() | |
else -> outputSize = (ceil(inputSize / 512.0) + 1).toInt() | |
} |
OlderNewer