|
#coding=utf-8
import argparse
import sounddevice as sd
import soundfile as sf
import numpy as np
import sys
import threading
import time
import thread
try:
import queue # Python 3.x
except ImportError:
import Queue as queue # Python 2.x
filename = 'G:\python\sq.wav'
file2_name = 'G:\python\jn.wav'
#####################################
def play_wav_file():
while True:
fs = 44100 # Hz
f = 440 # Hz
length = 100 # s
myarray = np.arange(fs * length)
myarray = np.sin(2 * np.pi * f / fs * myarray)
asio_out = sd.AsioSettings(channel_selectors=[0, 1])
sd.play(myarray,blocking=True,extra_settings=asio_out)
def print_time(threadName, delay):
count = 0
print ("2222222")
while True:
if (delay == 1):
fs = 44100 # Hz
f = 440 # Hz
length = 100 # s
myarray = np.arange(fs * length)
myarray = np.sin(2 * np.pi * f / fs * myarray)
asio_out = sd.AsioSettings(channel_selectors=[0, 1])
sd.play(myarray,blocking=True,extra_settings=asio_out)# , , extra_settings=asio_outprint ("###id %d" % delay)
try:
print(sd.query_devices())
print(sd.query_hostapis(2))
sd.default.samplerate = 44100
sd.default.device = 'Dante Virtual Soundcard'
# sd.default.dtype = 'int16'
# sd.default.channels = 2
#*************************直接调用这个函数就没问题
# play_wav_file()
#************************放在线程里调用就报错
"""
'Error opening {0}'.format(self.__class__.__name__))
File "C:\Python27\lib\site-packages\sounddevice.py", line 2561, in _check
raise PortAudioError(errormsg, err, hosterror_info)
sounddevice.PortAudioError: Error opening OutputStream: Unanticipated host error [PaErrorCode -9999]: 'Failed to load ASIO driver' [ASIO error 0]
"""
thread.start_new_thread(print_time, ("Thread-1",1))
# thread.start_new_thread(print_time, ("Thread-2", 2,))
# sd.stop()
print ("##### sd stop")
except:
print("Error: unable to start thread")
while 1:
pass
#############################sd.play(myarray,blocking=True,extra_settings=asio_out)# , , extra_settings=asio_out直接调用没有问题,但是在线程里调用就报错。哪位大哥给看看。谢谢
|
|