Generating a sine wave sound in python
问题 I've been trying to generate a sine wave using the following code and playing it thought my speakers, but it sounds horrible. Anyone knows why? It does not sound like a sine wave. dur = int(FS * float(duration) / 1000) for i in range(dur): a = frequency * i * 2 * math.pi / FS y = math.sin(a) outbuf[i] = y * 0.2 p = pyaudio.PyAudio() stream = p.open(format=pyaudio.paFloat32, channels=1, rate=44100, output=True) stream.write(outbuf) stream.stop_stream() stream.close() p.terminate() play_sound(