Skip to content

Audio capture is not functioning correctly and consistently results in saving only 1 second of audio. #119

@Dheeraj22dec

Description

@Dheeraj22dec

When using SensorManager to record an audio file using below code, the recording is for 10 seconds. However, the resulting file only captures 1 second of audio instead of the full 10 seconds. Additionally, attempts to import and play the recorded audio file doesn't have any sound.



**Initialisation of the sensor.**


 
sensorManager.init(
    sensorType = InternalSensorType.MICROPHONE,
    requireActivity(),
    requireActivity(),
    MicrophoneInitConfig(
        sampleRate = 16000,
       channelConfig = AudioFormat.CHANNEL_IN_MONO,
        audioFormat = AudioFormat.ENCODING_PCM_16BIT,
    ),
)

register the listener


sensorManager.registerListener(
    InternalSensorType.MICROPHONE,
    object : SensorManager.AppDataCaptureListener {
        override fun onStart(captureInfo: CaptureInfo) {
            handleOnStart()
        }

        override fun onStopped(captureInfo: CaptureInfo) {
            handleOnStopped()
        }

        override fun onCancelled(captureInfo: CaptureInfo?) {
            //   resetView()
        }

        override fun onRecordSaved(captureInfo: CaptureInfo) {
            Log.v("capture info","capture info"+captureInfo.captureFolder)
            findNavController().navigate(R.id.action_voice_recording_fragment_ui_to_voice_recording_preview_ui)
        }

        override fun onPostProcessed(processedInfo: ProcessedInfo) {
            processedInfo.result?.let { recordingResult.postValue(it) }
                ?: Log.v("","Prediction not received. Have you configured the credentials correctly? ")
        }

        override fun onError(exception: Exception, captureInfo: CaptureInfo?) {
            Log.v("","Error in prediction. ")
            Toast.makeText(requireContext(), "Check internet connection.", Toast.LENGTH_LONG).show()
        }
    }
)


start recording

sensorManager.start(
    InternalSensorType.MICROPHONE,
    MicrophoneCaptureRequest(
        externalIdentifier = "Patient1",
        outputFolder = "tbapp/recordings_${Instant.now()}",
        outputTitle = "Audio",
        outputFormat = "wav"
    )
)



 start the countdown






```

 countDownTimer =
    object : CountDownTimer(maxTimeCount, 100) {
        override fun onTick(millisUntilFinished: Long) {
            binding.aduioRecordProgress.progress = maxTimeCount.toInt() - millisUntilFinished.toInt()
            val progressText = "%.1f".format((binding.aduioRecordProgress.progress / 1000.0))
            binding.hintError.text = "$progressText sec"
        }

        override fun onFinish() {
            binding.hintError.text  = "10 sec"
            binding.aduioRecordProgress.progress = maxTimeCount.toInt()
            stopRecording()
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions