简体   繁体   中英

QAudioOutput strange peak sound at beginning in PyQt4

That's a general question: How can i get rid of the peak sound at the beginning of a sound? Here is the complete code so you can try it out. For comparison: if I play the same sound with QSound, it does not have that peak noise. But I can't use QSound because it does not work on Ubuntu.

If I am playing the sound in a player like VLC, there is no noise at the beginning. Here is the sound: http://www.file-upload.net/download-7876205/delete_2.wav.html

import struct, sys, time
from PyQt4.QtCore import QIODevice, Qt, QFile
from PyQt4.QtGui import QApplication, QWidget
from PyQt4.QtMultimedia import QAudio, QAudioDeviceInfo, QAudioFormat, QAudioOutput

class Window(QWidget):

    def __init__(self, parent = None):    
        QWidget.__init__(self, parent)

        format = QAudioFormat()
        format.setChannels(1)
        format.setFrequency(48000)
        format.setSampleSize(16)
        #format.setCodec("audio/pcm")
        format.setCodec("audio/wav")
        format.setByteOrder(QAudioFormat.LittleEndian)
        format.setSampleType(QAudioFormat.SignedInt)
        self.output = QAudioOutput(format, self)

        self.file=QFile()
        self.file.setFileName("C:\\delete_2.wav")
        self.file.open(QIODevice.ReadOnly)

        self.output.start(self.file)

        #self.file.close()

if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = Window()
    #window.show()
    sys.exit(app.exec_())
self.file.seek(44)

Is to skip file header, but 44 is not a fixed size. After that is audio data

Ah, the noise sound at the beginning disappears if there is

self.file.seek(44)

after

self.file.open(...)

What is this "seek"-thing for? Found it in a snippet and glad it works, but I'd like to understand the background!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM