class QVoiceRecorder(object): def __init__(self): pass def initAudioInput(self, filepath): self.recorder = QAudioRecorder() self.settings = QAudioEncoderSettings() self.settings.setCodec("audio/vorbis") self.recorder.setContainerFormat("ogg") #self.settings.setQuality(QtMultimedia.HighQuality) self.recorder.setEncodingSettings(self.settings) url = QtCore.QUrl.fromLocalFile( QtCore.QFileInfo(filepath).absoluteFilePath()) self.recorder.setOutputLocation(url) def start(self): self.recorder.record() def stop(self): self.recorder.pause() self.recorder.stop() self.recorder.stop()
class RecordAudio(object): recorder = None def __init__(self): pass def record(self, filename): url = QtCore.QUrl.fromLocalFile( QtCore.QFileInfo(filename).absoluteFilePath()) #content = QMediaObject(url) #self.recorder = QAudioRecorder() #source = QAudioInput() #source = QMediaObject() self.recorder = QAudioRecorder() settings = QAudioEncoderSettings() settings.setChannelCount(1) settings.setSampleRate(44100) settings.setBitRate(32) settings.setCodec("audio/vorbis") #settings.setEncodingMode(QtMultimedia.ConstantQualityEnconding) self.recorder.setContainerFormat("ogg") self.recorder.setEncodingSettings(settings) self.recorder.setOutputLocation(url) #container = None #self.recorder.setEncodingSettings(settings, container) def record(self): self.recorder.record() def stop(self): self.recorder.stop()