① python如何检听声卡是否有声音进来
检查声卡、音箱等设备是否毁坏,连接是否常,是独立声卡,取下声卡,用橡皮擦金手指,将声卡换一个插槽,再插紧。
② Python的几道关于声音处理的题目
第一题
x = [...];
min_val = min(x)
sx = sorted(x)
min_2_val = sx[1]
max_3_val = xs[-3]
第二题:
x = [...]
num_0 = 0 # 0点个数
list_0 = [] # 0点下标
for (i, y) in enumerate(x):
if y == 0:
num_0 += 1
list_0.append(i)
# 播放音频自己写吧
③ python 如何实现发出特定频率的声音
你是想使用winsound库吗?
winsound.Beep(frequency, ration)
④ python3.0怎样读取另一台电脑的系统声音,并在本机上报警提示
python版本切换全局版本切换:pyenv global anaconda-2.4.0全局切换为anaconda科学计算环境,因为,我现在也不做其他python开发,所以,无需再安装其他环境了。查看现在的python版本:michael@michael-ThinkCentre-XXXX:~$ pyenv versionssystem2.7.13.4.1* anaconda-2.4.0 (set by /home/michael/.pyenv/version)有全局版本切换,当然也会有局部环境的切换:在test文件夹下希望切换到python3.4.1:pyenv local python3.4.1
⑤ Python程序运行结束如何加入提示音
#以下都是基于win xp+py 2.x;其他操作系统及py3.x没试过...
1.电脑蜂鸣音:
print '\a'*7
#xp,py 2.6测试,这个绝对有BB...的声音。。。
2.播放外部音频文件
推荐外部模块:winsound
代码示例:
import winsound
PlaySound(sound)
#sound为wav文件名。
#还有其他播放其他多媒体格式的模块,可自行google下。
3.文本语音发音
#这个我曾用文本语音来代替程序运行的文字提示,搭建平台:
winxp+MS语音库+py_win32+py2.5(语音识别+文本发音)/py2.6(文本发音)+pyspeech(语音识别和发音模块)/pytts(仅文本发音)
*pywin32:http://sourceforge.net/projects/pywin32/
*pyspeech:http://code.google.com/p/pyspeech/
*To download Speech SDK 5.1, Visit http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=5e86ec97-40a7-453f-b0ee-6583171b4530; Only SpeechSDK51.exe and SpeechSDK51LangPack.exe are needed.
#如果仅仅是要发音:
speak('程序运行结束!')很简单;仅需winxp+MS语音库+py_win32+py2.5/py2.6
发音函数代码可以自己写!
⑥ 如何用python让树莓派发出声音
就是传递给函数raspberryTalk的参数。是不是很简单呢?其实我们就是利用mplayer来播放从google翻译传来的真人发声而已,就这么简单。
此外,如果你想通过终端来调整扬声器的音量,只需要输入alsamixer,然后通过向上和向下箭头来调整音量即可。 完整的代码可以在这里找到。
⑦ python turtle库 如何插入音乐
这个模块是用来画图的,不是用来播放音乐的,你可以参考这个github上的这个项目:
tjwei/Flappy-Turtle
它使用sys 和 subprocess模块调用系统第三方程序在后台播放音乐:
defplay_sound(name,vol=100):
file_name=name+".mp3"
ifsys.platform=="darwin":
cmds=["afplay"]
else:
cmds=["mplayer","-softvol","-really-quiet","-volume",str(vol)]
try:
Popen(cmds+[file_name])
except:
pass
如上代码所示,它使用了mplayer在后台播放音乐。
⑧ 用python的tkinter开发界面 能不能加入声音
用python的tkinter开发界面 能不能加入声音
1)引入抽象基类(Abstraact Base Classes,ABCs)。
2)容器类和迭代器类被ABCs化,所以cellections模块里的类型比Py2.5多了很多。
>>> import collections
>>> print('\n'.join(dir(collections)))
Callable
Container
Hashable
ItemsView
Iterable
Iterator
KeysView
Mapping
MappingView
MutableMapping
MutableSequence
MutableSet
NamedTuple
Sequence
Set
Sized
ValuesView
__all__
__builtins__
__doc__
__file__
__name__
_abcoll
_itemgetter
_sys
defaultdict
deque
另外,数值类型也被ABCs化。关于这两点,请参阅 PEP 3119和PEP 3141。
3)迭代器的next()方法改名为__next__(),并增加内置函数next(),用以调用迭代器的__next__()方法
4)增加了@abstractmethod和 @abstractproperty两个 decorator,编写抽象方法(属性)更加方便。
⑨ python 怎么录制系统声音不只是麦克风声音
#我可以帮你写一段代码,能够录音形成wav文件,不过要分析录音文件的波形,你可以另外找#工具,比如cooledit,也很方便。
from sys import byteorder
from array import array
from struct import pack
import pyaudio
import wave
THRESHOLD = 500
CHUNK_SIZE = 1024
FORMAT = pyaudio.paInt16
RATE = 44100
def is_silent(snd_data):
"Returns 'True' if below the 'silent' threshold"
return max(snd_data) < THRESHOLD
def normalize(snd_data):
"Average the volume out"
MAXIMUM = 16384
times = float(MAXIMUM)/max(abs(i) for i in snd_data)
r = array('h')
for i in snd_data:
r.append(int(i*times))
return r
def trim(snd_data):
"Trim the blank spots at the start and end"
def _trim(snd_data):
snd_started = False
r = array('h')
for i in snd_data:
if not snd_started and abs(i)>THRESHOLD:
snd_started = True
r.append(i)
elif snd_started:
r.append(i)
return r
# Trim to the left
snd_data = _trim(snd_data)
# Trim to the right
snd_data.reverse()
snd_data = _trim(snd_data)
snd_data.reverse()
return snd_data
def add_silence(snd_data, seconds):
"Add silence to the start and end of 'snd_data' of length 'seconds' (float)"
r = array('h', [0 for i in xrange(int(seconds*RATE))])
r.extend(snd_data)
r.extend([0 for i in xrange(int(seconds*RATE))])
return r
def record():
"""
Record a word or words from the microphone and
return the data as an array of signed shorts.
Normalizes the audio, trims silence from the
start and end, and pads with 0.5 seconds of
blank sound to make sure VLC et al can play
it without getting chopped off.
"""
p = pyaudio.PyAudio()
stream = p.open(format=FORMAT, channels=1, rate=RATE,
input=True, output=True,
frames_per_buffer=CHUNK_SIZE)
num_silent = 0
snd_started = False
r = array('h')
while 1:
# little endian, signed short
snd_data = array('h', stream.read(CHUNK_SIZE))
if byteorder == 'big':
snd_data.byteswap()
r.extend(snd_data)
silent = is_silent(snd_data)
if silent and snd_started:
num_silent += 1
elif not silent and not snd_started:
snd_started = True
if snd_started and num_silent > 30:
break
sample_width = p.get_sample_size(FORMAT)
stream.stop_stream()
stream.close()
p.terminate()
r = normalize(r)
r = trim(r)
r = add_silence(r, 0.5)
return sample_width, r
def record_to_file(path):
"Records from the microphone and outputs the resulting data to 'path'"
sample_width, data = record()
data = pack('<' + ('h'*len(data)), *data)
wf = wave.open(path, 'wb')
wf.setnchannels(1)
wf.setsampwidth(sample_width)
wf.setframerate(RATE)
wf.writeframes(data)
wf.close()
if __name__ == '__main__':
print("please speak a word into the microphone")
record_to_file('demo.wav')
print("done - result written to demo.wav")
⑩ 用python的tkinter开发界面 能不能加入声音
可以调用pygame模块加入声音,安装一下