al.zatv
al.zatv

Reputation: 193

qt5 on android don't record PCM wav files with QAudioRecorder

I wrote code on pyqt5 to record audio files in PCM codec to wav format. And it is fine on PC, but on android it is always write mp4 files with amr codec. How can i fix it?

Here is the code

recorder=QAudioRecorder(w)

audioSettings=QAudioEncoderSettings()
audioSettings.setCodec("audio/PCM")
audioSettings.setSampleRate(16000)
recorder.setAudioSettings(audioSettings);

recorder.setContainerFormat("wav");
recorder.setOutputLocation(QUrl.fromLocalFile("/sdcard/test"))

(Pyqt5 installed from pip in Pydroid 2 app on android, qt5 from Ministro II app)

Upvotes: 1

Views: 616

Answers (1)

al.zatv
al.zatv

Reputation: 193

Unfortunately, I don't solve the problem with QAudioRecorder. I find the way to write headerless signed-int 16bit 16khz little endian PCM with QAudioInput:

#!/usr/bin/env python2
from PyQt5.QtCore import QFile
from PyQt5.QtMultimedia import QAudioInput,QAudioFormat,QAudio
import sys
import time
from PyQt5.QtWidgets import QApplication, QWidget,QPushButton

format=QAudioFormat()
format.setSampleRate(16000);
format.setChannelCount(1);
format.setSampleSize(16);
format.setCodec("audio/pcm")

format.setByteOrder(QAudioFormat.LittleEndian)
format.setSampleType(QAudioFormat.SignedInt)

audio=QAudioInput(format)

def onBtn():
    if audio.state()==QAudio.StoppedState:
        audio.start(destFile)
        print "started"
    else:
        audio.stop()
        print "stopped"
pass

app = QApplication(sys.argv)
w = QWidget()
btnRec = QPushButton('Rec|stop', w)
btnRec.clicked.connect(onBtn)
w.show()
app.exec_()

destFile.close()

Upvotes: 0

Related Questions