找回密码
 立即注册

扫一扫,访问微社区

QQ登录

只需一步,快速开始

查看: 2085|回复: 1

[求助] 两个地方调用竟然不一样,大侠给看看。

2

主题

2

帖子

2

积分

贫民

积分
2
ShuRenZhou 发表于 2018-4-19 17:49:03 | 显示全部楼层 |阅读模式
#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直接调用没有问题,但是在线程里调用就报错。哪位大哥给看看。谢谢
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表