我对python很陌生,我一直在研究一个简单的程序,它可以录制声音,稍微修改一下,然后播放它。我在 Visual Studio 中编写了它,但是这个软件对我不起作用,sounddevice
并且说No module named '_sounddevice_data'
但是当我python "path to this file"
在 Anaconda Prompt 中运行它时,它可以正常工作。这个包在我使用的 Visual 的 python 环境中 - Anaconda 5.2.0
。另一方面,由于在 Visual 中跳过了一些错误,从 Anaconda Prompt 运行将无法使用 tensorflow Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2
。更重要的是,当我使用简单的 .bat 文件运行此代码时,一切都很好:D
echo off
CALL D:\Users\blaze\Anaconda3\Scripts\activate.bat D:\Users\blaze\Anaconda3
python C:\Users\blaze\source\repos\recorder\recorder\recorder.py
echo on
我会很感激任何帮助,因为我无法理解发生了什么。这是代码:
import tensorflow as tf
import numpy as np
import time
import glob
import os
model=tf.keras.models.load_model("D:\Projekt\ML\save\model.h5py",compile=True)
duration = 100 # seconds
frames = 8192
global a
a=0
file_list_c = glob.glob(os.path.join(os.getcwd(), "Check", "*.txt"))
for file_path in file_list_c:
with open(file_path) as f:
datax =np.genfromtxt(file_path)
datax=np.reshape(datax,(-1,8192))
print(model.predict(datax))
print(np.argmax(model.predict(datax)))
import sounddevice as sd
def callback(indata, outdata, frames, time, status):
if status:
print(status)
print(np.argmax(model.predict(np.reshape(indata,(-1,8192)))))
outdata[:] = indata
with sd.Stream(samplerate=48000,blocksize=8192,channels=1, callback=callback):
sd.sleep(int(duration*1000))
time.sleep(100)