Python 十六进制转义如何与PyAudio中的音频关联?

Python 十六进制转义如何与PyAudio中的音频关联?,python,audio,hex,wav,pyaudio,Python,Audio,Hex,Wav,Pyaudio,我正在玩PyAudio,试图制作一些微调音乐,但似乎无法启动。我在程序中使用core audio时发现了以下代码: 我做了一些小的调整: import time import pyaudio # Open the stream stream=pyaudio.PyAudio().open(format=pyaudio.paInt8,channels=1,rate=24000,output=True) # Amount of time for wave to be played in secon

我正在玩PyAudio,试图制作一些微调音乐,但似乎无法启动。我在程序中使用core audio时发现了以下代码: 我做了一些小的调整:

import time
import pyaudio

# Open the stream
stream=pyaudio.PyAudio().open(format=pyaudio.paInt8,channels=1,rate=24000,output=True)

# Amount of time for wave to be played in seconds
length = 1

# Now generate the 1KHz signal at the speakers/headphone output
# Sine wave, to 8 bit depth
start = time.clock()
while time.clock() - start <= length:
    stream.write("\x00\x30\x5a\x76\x7f\x76\x5a\x30\x00\xd0\xa6\x8a\x80\x8a\xa6\xd0")

# Close the open _channel(s)_
stream.close()
pyaudio.PyAudio().terminate()
据我所知,十六进制转义是发送到音频输出的原始音频。我把它们放进了一个十六进制转换器,并用图表表示了它们的值。这看起来确实像是一个正弦波,但我仍然无法更直观地理解发生了什么。我的最终目标是编写一个函数,该函数可以在一系列十六进制转义中输出任意给定的频率,并写入流中。一个bytestring中包含多少个样本,它们代表什么值,即什么值表示正弦波在全体积下的波峰、波谷和静止状态