Exemplo n.º 1
0
    def __setRecordParams(self):  ##设置音频输入参数
        selectedFile = self.ui.editOutputFile.text().strip()
        if (selectedFile == ""):
            QMessageBox.critical(self, "错误", "请先设置录音输出文件")
            return False

        if os.path.exists(selectedFile):
            os.remove(selectedFile)  # 删除已有文件
        ##         QMessageBox.critical(self,"错误","录音输出文件被占用,无法删除")
        ##         return False

        recordFile = QUrl.fromLocalFile(selectedFile)
        self.recorder.setOutputLocation(recordFile)  # 设置输出文件

        recordDevice = self.ui.comboDevices.currentText()
        self.recorder.setAudioInput(recordDevice)  # 设置录入设备

        settings = QAudioEncoderSettings()  # 音频编码设置
        settings.setCodec(self.ui.comboCodec.currentText())  # 编码

        sampRate = int(self.ui.comboSampleRate.currentText())
        settings.setSampleRate(sampRate)  # 采样率

        channelCount = int(self.ui.comboChannels.currentText())
        settings.setChannelCount(channelCount)  # 通道数

        settings.setEncodingMode(QMultimedia.ConstantBitRateEncoding)  # 固定比特率

        self.recorder.setAudioSettings(settings)  # 音频设置
        return True
Exemplo n.º 2
0
class SimpleAudioRecorder(QAudioRecorder):
    def __init__(self, data: ConverterData, transcription: Transcription,
                 app_settings: AppSettings) -> None:
        super().__init__()
        self.app_settings = app_settings
        self.temp = data.get_temp_file()
        self.transcription = transcription
        self.file_path = os.path.join(self.temp,
                                      f'{self.transcription.id}.wav')
        self.settings = QAudioEncoderSettings()

    def start_recording(self) -> None:
        LOG_RECORDER.info("Audio recording started.")
        self.settings.setCodec('audio/pcm')
        self.settings.setChannelCount(1)
        self.settings.setBitRate(96000)
        self.settings.setSampleRate(44100)
        self.settings.setQuality(self.app_settings.audio_quality)
        self.settings.setEncodingMode(QMultimedia.ConstantQualityEncoding)
        container = 'audio/x-wav'
        self.setEncodingSettings(self.settings, QVideoEncoderSettings(),
                                 container)
        self.setOutputLocation(QUrl.fromLocalFile(self.file_path))
        self.record()

    def stop_recording(self) -> Union[str, None]:
        LOG_RECORDER.info("Audio recording finished.")
        LOG_RECORDER.info(f"Audio file: {self.file_path}")
        self.stop()
        return self.file_path
Exemplo n.º 3
0
    def __setRecordParams(self):  ##设置音频输入参数
        selectedFile = self.ui.editOutputFile.text().strip()
        if (selectedFile == ""):
            QMessageBox.critical(self, "错误", "请先设置录音输出文件")
            return False

        if os.path.exists(selectedFile):
            os.remove(selectedFile)  #删除已有文件

    ##         QMessageBox.critical(self,"错误","录音输出文件被占用,无法删除")
    ##         return False

        recordFile = QUrl.fromLocalFile(selectedFile)
        self.recorder.setOutputLocation(recordFile)  #设置输出文件

        recordDevice = self.ui.comboDevices.currentText()
        self.recorder.setAudioInput(recordDevice)  #设置录入设备

        settings = QAudioEncoderSettings()  #音频编码设置
        settings.setCodec(self.ui.comboCodec.currentText())  #编码

        sampRate = int(self.ui.comboSampleRate.currentText())
        settings.setSampleRate(sampRate)  #采样率

        bitRate = int(self.ui.comboBitrate.currentText())
        settings.setBitRate(bitRate)  #比特率

        channelCount = int(self.ui.comboChannels.currentText())
        settings.setChannelCount(channelCount)  #通道数

        ##      quality=self.ui.sliderQuality.value()   #也可以
        quality = QMultimedia.EncodingQuality(self.ui.sliderQuality.value())
        settings.setQuality(quality)  #品质

        if self.ui.radioQuality.isChecked():  #编码模式为固定品质,自动决定采样率,采样点大小
            settings.setEncodingMode(QMultimedia.ConstantQualityEncoding)
        else:
            settings.setEncodingMode(
                QMultimedia.ConstantBitRateEncoding)  #固定比特率

        self.recorder.setAudioSettings(settings)  #音频设置
        return True
Exemplo n.º 4
0
    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)
Exemplo n.º 5
0
    def __init__(self):
        super(App, self).__init__()
        self.loginButton.clicked.connect(self.showLoginDialog)
        self.client_thread.text_signal.connect(self.showText)  # 显示文本消息
        self.client_thread.usr_signal.connect(self.showUserList)  # 更新在线用户
        self.client_thread.file_signal.connect(self.showFile)  # 显示文件消息
        self.emojis.emoji_signal.connect(self.addEmoji)

        # 通过QListWidget的当前item变化来切换QStackedWidget中的序号
        self.userListWidget.currentRowChanged.connect(self.dialogChanged)

        self.usrList = []  # 保存上一次的在线用户列表
        self.groupList = []  # 群组列表

        self.md5 = hashlib.md5()  # 用于加密密码

        # 录音机
        self.recorder = QAudioRecorder(self)
        settings = QAudioEncoderSettings()
        settings.setChannelCount(2)
        settings.setSampleRate(16000)
        self.recorder.setEncodingSettings(settings)