起こっている問題
以下のコード(実際のコードから問題部分を簡略化して抜粋)にて振幅=amplitudeを1.0から1.1など1.0より大きい値に変更しただけで、音が高く?なってしまいます。
なぜこのような挙動になるのでしょうか?
恐縮ですがお力添えいただけたら幸いです。 よろしくお願いいたします。
python
1import numpy as np 2import matplotlib.pyplot as plt 3import pyaudio 4import struct 5 6 7def oscillate(time, frequency): 8 """Generate a point of sine wave""" 9 return np.sin(2.0*np.pi*frequency*time) 10 11def amplitude(): 12 """Return amplitude""" 13 return 1.0 # [Changing this amplitude to a value that is greater than 1.0 14 # causes the problem] 15 16 17# Generate 1 second of sine wave 18RATE = 44100 19time = np.linspace(0, RATE, RATE) 20frequency = 440 21wave = amplitude() * oscillate(time, frequency) 22 23# Prepare to play the sine wave as sound 24chunkSize = 1024 25p = pyaudio.PyAudio() 26stream = p.open( 27 format=pyaudio.paInt16, 28 channels=1, 29 rate=RATE, 30 frames_per_buffer=chunkSize, 31 output=True 32 ) 33 34# Play 35while stream.is_active(): 36 chunk = wave 37 chunk = (chunk * 32768.0).astype(np.int16) 38 chunk = struct.pack("h" * len(chunk), *chunk) 39 stream.write(chunk) 40 41stream.stop() 42stream.close() 43p.terminate()

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/05 09:02
2019/08/06 00:33
2019/08/06 02:31
2019/08/06 15:51
2019/08/07 06:57