Beispiel #1
0
    def setAudioDevice(self, audioDevice=None):
        if audioDevice:
            self.audioDevice = audioDevice
        sampleSize = 32 if 32 in self.audioDevice.supportedSampleSizes(
        ) else 16
        sampleRate = 48000 if 48000 in self.audioDevice.supportedSampleRates(
        ) else 44100

        format = QtMultimedia.QAudioFormat()
        format.setSampleRate(sampleRate)
        format.setChannelCount(2)
        format.setSampleSize(sampleSize)
        format.setCodec('audio/pcm')
        format.setByteOrder(QtMultimedia.QAudioFormat.LittleEndian)
        format.setSampleType(QtMultimedia.QAudioFormat.Float if sampleSize >=
                             32 else QtMultimedia.QAudioFormat.SignedInt)

        if not self.audioDevice.isFormatSupported(format):
            format = self.audioDevice.nearestFormat(format)
            #do something else with self.audioDevice.nearestFormat(format)?
        self.sampleSize = format.sampleSize()
        self.sampleRate = format.sampleRate()
        try:
            self.output.notify.disconnect()
            del self.output
        except:
            pass
        self.output = QtMultimedia.QAudioOutput(self.audioDevice, format)
        self.output.setNotifyInterval(25)
        self.output.stateChanged.connect(self.stateChanged)
Beispiel #2
0
 def set_audio_device(self):
     format = QtMultimedia.QAudioFormat()
     format.setSampleRate(self.audio_rate)
     format.setChannelCount(1)
     format.setByteOrder(QtMultimedia.QAudioFormat.LittleEndian)
     format.setSampleType(QtMultimedia.QAudioFormat.Float)
     if (self.audio_device.isFormatSupported(format) is not True):
         format = self.audio_device.nearestFormat(format)
     self.audio_rate = format.sampleRate()
     self.audio_bytes = format.bytesPerFrame()
     if self.audio_input:
         self.audio_input.stop()
     else:
         print("Init Audio")
     self.audio_input = QtMultimedia.QAudioInput(self.audio_device, format)
     self.audio_nsamples = self.audio_rate // 2
     self.nfft, self.noverlap = fft_optim(Fs=self.audio_rate,
                                          code_speed=self.wpm)
     self.fftLabel.setText(f'FFT {self.nfft} OVL {self.noverlap}')
     #print(f"FFT {self.nfft} with overlap {self.noverlap}")
     self.sc_time.set_mp(self.audio_nsamples)
     self.sc_peak.set_mp(self.audio_rate)
     self.audio_input.setBufferSize(self.audio_nsamples)
     self.initTEnv()
     self.audio_buffer = self.audio_input.start()
     self.audio_buffer.readyRead.connect(self.audioRead)
     self.predworker.reset_hist()
Beispiel #3
0
 def __init__(self):
     QtWidgets.QWidget.__init__(self , None)
     self.widget = QtWidgets.QWidget(self)
     self.plate = Plate(self.widget)
     self.layout = FixedARLayout(self.widget , 1.2)
     self.layout.addWidget(self.plate)
     self.widget.setLayout(self.layout)
     self.setCentralWidget(self.widget)
     self.statusbar = QtWidgets.QStatusBar(self)
     self.setStatusBar(self.statusbar)
     self.label_digitize = QtWidgets.QLabel(self.statusbar)
     self.label_digitize.setText("DIGITIZE")
     self.green_led_on = QtGui.QPixmap(":/led-green-on.bmp")
     self.green_led_off = QtGui.QPixmap(":/led-green-off.bmp")
     self.yellow_led_on = QtGui.QPixmap(":/led-yellow-on.bmp")
     self.yellow_led_off = QtGui.QPixmap(":/led-yellow-off.bmp")
     self.led_digitize = QtWidgets.QLabel(self.statusbar)
     self.led_digitize.setPixmap(self.green_led_off)
     self.label_menu = QtWidgets.QLabel(self.statusbar)
     self.label_menu.setText("MENU")
     self.led_menu = QtWidgets.QLabel(self.statusbar)
     self.led_menu.setPixmap(self.yellow_led_off)
     self.label_error = QtWidgets.QLabel(self.statusbar)
     self.label_error.setText("ERROR")
     self.led_error = QtWidgets.QLabel(self.statusbar)
     self.led_error.setPixmap(self.yellow_led_off)
     self.statusbar.addPermanentWidget(self.label_digitize)
     self.statusbar.addPermanentWidget(self.led_digitize)
     self.statusbar.addPermanentWidget(self.label_menu)
     self.statusbar.addPermanentWidget(self.led_menu)
     self.statusbar.addPermanentWidget(self.label_error)
     self.statusbar.addPermanentWidget(self.led_error)
     self.conn_msg = ""
     self.adi = QtMultimedia.QAudioDeviceInfo.defaultOutputDevice()
     self.tmr = QtCore.QTimer(self)
     self.tmr.timeout.connect(self.push_audio)
     af = QtMultimedia.QAudioFormat()
     af.setByteOrder(QtMultimedia.QAudioFormat.LittleEndian)
     af.setChannelCount(1)
     af.setCodec("audio/pcm")
     af.setSampleRate(11025)
     af.setSampleSize(16)
     af.setSampleType(QtMultimedia.QAudioFormat.SignedInt)
     self.audio_lock = threading.RLock()
     self.audio_running = False
     self.out = QtMultimedia.QAudioOutput(self.adi , af , self)
     self.out.stateChanged.connect(self.stateChanged)
     # 40 ms of audio buffer
     self.out.setBufferSize(round(11025.0 * 0.04 * 2))
     self.audio_io = self.out.start()
Beispiel #4
0
    def initAudioPlayer(self):
        self.qbyte_array = QtCore.QByteArray()
        self.buffer = QtCore.QBuffer()

        audioFormat = QtMultimedia.QAudioFormat()
        audioFormat.setSampleRate(self.sr)
        audioFormat.setChannelCount(1)
        audioFormat.setSampleSize(16)
        audioFormat.setCodec('audio/pcm')
        audioFormat.setByteOrder(QtMultimedia.QAudioFormat.LittleEndian)
        audioFormat.setSampleType(QtMultimedia.QAudioFormat.SignedInt)

        deviceInfo = QtMultimedia.QAudioDeviceInfo(
            QtMultimedia.QAudioDeviceInfo.defaultOutputDevice())
        if not deviceInfo.isFormatSupported(audioFormat):
            print(
                'Raw audio format not supported by backend, cannot play audio.'
            )
            return

        self.audioPlayer = QtMultimedia.QAudioOutput(audioFormat, self)
Beispiel #5
0
    def __init__(self):
        self.m_device = QtMultimedia.QAudioDeviceInfo.defaultOutputDevice()
        self.m_output = None

        self.m_format = QtMultimedia.QAudioFormat()
        self.m_format.setSampleRate(16000)
        self.m_format.setChannelCount(1)
        self.m_format.setSampleSize(16)
        self.m_format.setCodec('audio/pcm')
        self.m_format.setByteOrder(QtMultimedia.QAudioFormat.LittleEndian)
        self.m_format.setSampleType(QtMultimedia.QAudioFormat.SignedInt)

        info = QtMultimedia.QAudioDeviceInfo(
            QtMultimedia.QAudioDeviceInfo.defaultOutputDevice())
        if not info.isFormatSupported(self.m_format):
            QtCore.qWarning(
                "Default format not supported - trying to use nearest")
            self.m_format = info.nearestFormat(self.m_format)
        super(AudioOutput, self).__init__(self.m_device, self.m_format)
        self.setNotifyInterval(1)
        self.setBufferSize(6400)
Beispiel #6
0
import matplotlib.pyplot as plt
import PyQt5
from PyQt5 import QtMultimedia
from PyQt5.QtWidgets import QApplication, QWidget
import sys
import text2speech
from text2speech import Ws_Param
import forward
plt.rcParams['font.sans-serif']=['SimHei']
plt.rcParams['axes.unicode_minus'] = False

app = QApplication(sys.argv)
format = QtMultimedia.QAudioFormat()
format.setChannelCount(2)
format.setSampleRate(8000)
format.setSampleSize(16)
format.setCodec("audio/pcm")
format.setByteOrder(QtMultimedia.QAudioFormat.LittleEndian)
format.setSampleType(QtMultimedia.QAudioFormat.UnSignedInt)
audio_output = QtMultimedia.QAudioOutput(format)

rfile = PyQt5.QtCore.QFile()




    plt.title('这是'+title)

    wsParam = Ws_Param(APPID='5e2faa83', APIKey='58c05763b09a8d85d9a2f5645f981824',
                    APISecret='1d83a8338cc3e0188c880b9ab514770e',
                    Text='这是'+title)
Beispiel #7
0
    def __init__(self, parent=None):
        super(Display, self).__init__(parent)

        # Set pause_emulation as disabled
        global pause_emulation
        pause_emulation = False

        # Set parent window as attr
        self.parent = parent
        # Define total frames executed as 0
        self.frames = 0
        # Define turbo as disabled
        self.turbo = False
        # Set screen buffers in VDP
        self.set_vdp_buffers()
        self.set_audio_buffer()
        # Define frame elapsed times (fps) as deque
        self.frame_times = deque([20], 1000)

        # Start a timer for run frames every 16ms
        timer = qt.QTimer(self)
        timer.timeout.connect(self.frame)
        timer.setInterval(16)
        timer.start()
        self.timer = timer

        audio_format = qtm.QAudioFormat()
        audio_format.setSampleRate(44100)
        audio_format.setChannelCount(2)
        audio_format.setSampleSize(32)
        audio_format.setCodec("audio/pcm")
        audio_format.setByteOrder(qtm.QAudioFormat.LittleEndian)
        audio_format.setSampleType(qtm.QAudioFormat.SignedInt)
        self.audio_output = qtm.QAudioOutput(audio_format, self)
        self.audio_output.setVolume(1)
        self.audio_output.setBufferSize(audio_buffer_size)
        self.sample = qt.QBuffer()
        # Define last_fps_time as current time in timer
        self.last_fps_time = qt.QTime.currentTime()

        # Initialize debugger windows
        self.cram_debug = CramDebug()
        self.vram_debug = VramDebug()
        self.m68k_debug = M68kDebug()
        self.z80_debug = Z80Debug()
        self.bp_debug = BreakpointDebug()

        # Set display placeholder
        self.label = qtw.QLabel("<h1 style='color: #03a9f4'>KAISER</h1>" +
                                "<span style='color: #eceff1'>Debugger<span>")
        self.label.setAlignment(qt.Qt.AlignCenter)
        self.label.setStyleSheet(
            "background-color: #212121; color: #424242; font-family: Verdana")
        self.label.show()

        # Start Frame
        self.frame()

        # Create a Grid Layout
        self.layout = qtw.QGridLayout()
        self.layout.setRowMinimumHeight(0, 240)
        self.layout.setColumnMinimumWidth(1, 400)
        # Add Screen Display to Grid Layout
        self.layout.addWidget(self.label, 0, 1, 1, 2)
        # Set no margins on Grid Layout
        self.layout.setContentsMargins(0, 0, 0, 0)
        # Set Grid Layout as Window Layout
        self.setLayout(self.layout)
        # Adjust Window Size
        self.adjustSize()
        # Create Window Menus
        self.create_menus()
Beispiel #8
0
    def __init__(self, *args, **kwargs):
        
        # Setup widget
        QtWidgets.QWidget.__init__(self, *args, **kwargs)
        loader = UiLoader()
        loader.registerCustomWidget(QTableWidgetMetronome)
        loader.load(LocalPath('metronome.ui'), self)
        
        #
        # Setup initial values
        #

        self._externalTimerIndex = -1
        self._MetronomeIndex = 0
        self._MetronomeLoud = True
        self._TimerConnected = False

        # Perform autoconfig
        AutoConfig.__init__(self, autoconfig_name_key='metronome')
        
        # Empty array of emph buttons
        self._pushButtons_Click = []
        
        #
        # Connect widgets!
        #

        # Metronome sound
        AudioFormat = QtMultimedia.QAudioFormat()
        AudioFormat.setChannelCount(1)
        AudioFormat.setSampleRate(44100)
        AudioFormat.setSampleSize(16)
        AudioFormat.setCodec("audio/pcm")
        AudioFormat.setByteOrder(QtMultimedia.QAudioFormat.LittleEndian)
        AudioFormat.setSampleType(QtMultimedia.QAudioFormat.SignedInt)
        
        self.MetronomeOutput = QtMultimedia.QAudioOutput(AudioFormat)
        self.MetronomeOutput.setVolume(1.0)
        self.MetronomeBuffer = QtCore.QBuffer()
        self.MetronomeDataSilent = QtCore.QByteArray()
        self.MetronomeDataQuiet = QtCore.QByteArray()
        self.MetronomeDataLoud = QtCore.QByteArray()

        self._make_click()
        
        # Metronome Flash timer
        self.MetronomeTimer = QtCore.QTimer()
        self.MetronomeTimer.setTimerType(QtCore.Qt.PreciseTimer)
        
        # Metronome MetronomeUnFlash timer
        self.MetronomeUnFlashTimer = QtCore.QTimer()
        self.MetronomeUnFlashTimer.setTimerType(QtCore.Qt.PreciseTimer)

        # Start / stop metronome
        self.comboBox_Metronome.currentIndexChanged.connect(self.MetronomeStartStop)
        
        # Spinboxes: if metronome is running, change speed / emphasis based on changes
        self.BPM_spinBox.setKeyboardTracking(False)
        self.BPM_spinBox.valueChanged.connect(self.MetronomeUpdate)

        self.Emph_spinBox.setKeyboardTracking(False)
        self.Emph_spinBox.valueChanged.connect(self.emphUpdate)
        
        # Build button array
        self.emphUpdate()

        self.spinBox_Skipped.setKeyboardTracking(False)
        self.spinBox_Skipped.valueChanged.connect(self.MetronomeUpdate)

        # Presets
        self.pushButton_Preset_1.clicked.connect(lambda: self.Preset(1))
        self.pushButton_Preset_2.clicked.connect(lambda: self.Preset(2))
        self.pushButton_Preset_5.clicked.connect(lambda: self.Preset(5))
        self.pushButton_Preset_10.clicked.connect(lambda: self.Preset(10))

        # Table mode
        self.tableWidgetMetronome.setColumnCount(4)
        self.tableWidgetMetronome.setRowCount(0)
        self.tableWidgetMetronome.setHorizontalHeaderLabels(
                ["Duration", "BPM", "Beats per measure", "Skipped"]
                )
        self.tableWidgetMetronome.setFixedWidth()