In [2]:
import pyaudio

In [7]:
"""PyAudio Example: Play a WAVE file."""

import pyaudio
import wave
import sys
import time

CHUNK = 1024

fname = "/home/bird/Desktop/test48k.wav"

wf = wave.open(fname, 'rb')

device_index = 31

p = pyaudio.PyAudio()

def callback(in_data, frame_count, time_info, status):
    data = wf.readframes(frame_count)
    return (data, pyaudio.paContinue)

stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
                channels=wf.getnchannels(),
                rate=wf.getframerate(),
                output=True,
                output_device_index=device_index,
                stream_callback=callback)

stream.start_stream()

while stream.is_active():
    time.sleep(0.1)
    
stream.stop_stream()
stream.close()


---------------------------------------------------------------------------
IOError                                   Traceback (most recent call last)
<ipython-input-7-27c37e7f7ded> in <module>()
     25                 output=True,
     26                 output_device_index=device_index,
---> 27                 stream_callback=callback)
     28 
     29 stream.start_stream()

/usr/local/anaconda/lib/python2.7/site-packages/pyaudio.pyc in open(self, *args, **kwargs)
    745         """
    746 
--> 747         stream = Stream(self, *args, **kwargs)
    748         self._streams.add(stream)
    749         return stream

/usr/local/anaconda/lib/python2.7/site-packages/pyaudio.pyc in __init__(self, PA_manager, rate, channels, format, input, output, input_device_index, output_device_index, frames_per_buffer, start, input_host_api_specific_stream_info, output_host_api_specific_stream_info, stream_callback)
    440 
    441         # calling pa.open returns a stream object
--> 442         self._stream = pa.open(**arguments)
    443 
    444         self._input_latency = self._stream.inputLatency

IOError: [Errno Device unavailable] -9985

In [27]:
stream.close()

p.terminate()

In [24]:
p = None
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
                channels=wf.getnchannels(),
                rate=wf.getframerate(),
                output=True,
                output_device_index=device_index,
                stream_callback=callback)


---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-24-c81699cb4105> in <module>()
      1 
      2 p = None
----> 3 stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
      4                 channels=wf.getnchannels(),
      5                 rate=wf.getframerate(),

AttributeError: 'NoneType' object has no attribute 'open'

In [3]:
p = pyaudio.PyAudio()
for index in range(p.get_device_count()):
    print index, p.get_device_info_by_index(index)['name']
p.terminate()


0 default
1 Adapter 1 (5316) - Input Stream 1
2 Adapter 1 (5316) - Input Stream 2
3 Adapter 1 (5316) - Input Stream 3
4 Adapter 1 (5316) - Input Stream 4
5 Adapter 1 (5316) - Input Stream 5
6 Adapter 1 (5316) - Input Stream 6
7 Adapter 1 (5316) - Input Stream 7
8 Adapter 1 (5316) - Input Stream 8
9 Adapter 1 (5316) - Input Stream 9
10 Adapter 1 (5316) - Input Stream 10
11 Adapter 1 (5316) - Input Stream 11
12 Adapter 1 (5316) - Input Stream 12
13 Adapter 1 (5316) - Input Stream 13
14 Adapter 1 (5316) - Input Stream 14
15 Adapter 1 (5316) - Input Stream 15
16 Adapter 1 (5316) - Input Stream 16
17 Adapter 1 (5316) - Output Stream 1
18 Adapter 1 (5316) - Output Stream 2
19 Adapter 1 (5316) - Output Stream 3
20 Adapter 1 (5316) - Output Stream 4
21 Adapter 1 (5316) - Output Stream 5
22 Adapter 1 (5316) - Output Stream 6
23 Adapter 1 (5316) - Output Stream 7
24 Adapter 1 (5316) - Output Stream 8
25 Adapter 1 (5316) - Output Stream 9
26 Adapter 1 (5316) - Output Stream 10
27 Adapter 1 (5316) - Output Stream 11
28 Adapter 1 (5316) - Output Stream 12
29 Adapter 1 (5316) - Output Stream 13
30 Adapter 1 (5316) - Output Stream 14
31 Adapter 1 (5316) - Output Stream 15
32 Adapter 1 (5316) - Output Stream 16

In [4]:
p = pyaudio.PyAudio()

In [ ]:
p.get_d