ubuntu上でjupyterを使って音声を保存しようとしていますがうまく行きません。
jupyterの画面をどう貼り付ければいいかわからないのでベタうちしますが
jupyter
1 2!pip install pyaudio 3 4Requirement already satisfied: pyaudio in /home/kokawa2003/work/Voice_Emotion/venv/lib/python3.6/site-packages (0.2.11) 5 6!pip install wave 7 8Requirement already satisfied: wave in /home/kokawa2003/work/Voice_Emotion/venv/lib/python3.6/site-packages (0.0.2) 9 10import pyaudio 11 12import wave 13 14 15 16CHUNK = 1024 17 18FORMAT = pyaudio.paInt16 #paInt8 19 20CHANNELS = 2 21 22RATE = 44100 #sample rate 23 24RECORD_SECONDS = 4 25 26WAVE_OUTPUT_FILENAME = "output10.wav" 27 28 29 30p = pyaudio.PyAudio() 31 32 33 34stream = p.open(format=FORMAT, 35 36 channels=CHANNELS, 37 38 rate=RATE, 39 40 input=True, 41 42 frames_per_buffer=CHUNK) #buffer 43 44 45 46print("* recording") 47 48 49 50frames = [] 51 52 53 54for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)): 55 56 data = stream.read(CHUNK) 57 58 frames.append(data) # 2 bytes(16 bits) per channel 59 60 61 62print("* done recording") 63 64 65 66stream.stop_stream() 67 68stream.close() 69 70p.terminate() 71 72 73 74wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb') 75 76wf.setnchannels(CHANNELS) 77 78wf.setsampwidth(p.get_sample_size(FORMAT)) 79 80wf.setframerate(RATE) 81 82wf.writeframes(b''.join(frames)) 83 84wf.close() 85 86--------------------------------------------------------------------------- 87ImportError Traceback (most recent call last) 88<ipython-input-6-fea9d252a229> in <module> 89----> 1 import pyaudio 90 2 import wave 91 3 92 4 CHUNK = 1024 93 5 FORMAT = pyaudio.paInt16 #paInt8 94 95ImportError: No module named 'pyaudio' 96 97
このような感じでPIPでpyaudioはinstallされているのに
ImportError: No module named 'pyaudio'
になります。なぜでしょう?
import sys
print(sys.prefix)
print(sys.path)
をjupyterで実行した結果を追記してみてください。
回答1件
あなたの回答
tips
プレビュー