import pyAudioGraph as ag

# choose a wav file on your pc
wav_file = 'AudioFile.wav'  # only signed 16/32 bit supported

"""
Explanation: Table of Contents
<p><div class="lev1 toc-item"><a href="#Create-the-units" data-toc-modified-id="Create-the-units-1"><span class="toc-item-num">1&nbsp;&nbsp;</span>Create the units</a></div><div class="lev1 toc-item"><a href="#Connect-the-units" data-toc-modified-id="Connect-the-units-2"><span class="toc-item-num">2&nbsp;&nbsp;</span>Connect the units</a></div><div class="lev1 toc-item"><a href="#Append-the-nodes-and-then-sort-the-graph" data-toc-modified-id="Append-the-nodes-and-then-sort-the-graph-3"><span class="toc-item-num">3&nbsp;&nbsp;</span>Append the nodes and then sort the graph</a></div><div class="lev1 toc-item"><a href="#Run" data-toc-modified-id="Run-4"><span class="toc-item-num">4&nbsp;&nbsp;</span>Run</a></div>
End of explanation
"""


world = ag.World(nchannels=2, buf_len=512)

# create the diskInUnit
audioStream = ag.AudioStreamWaveFile(wav_file)
diskInNode = ag.Nodes.DiskInNode(world, audioStream)

# create the output Unit
outNode = ag.Nodes.OutNode(world)

"""
Explanation: Create the units
End of explanation
"""


for i in range(diskInNode.nchannels):
    diskInNode.w_out[i].plug_into(outNode.w_in[i])

"""
Explanation: Connect the units
End of explanation
"""


world.append(outNode)
world.sort()

"""
Explanation: Append the nodes and then sort the graph
End of explanation
"""


import time
world.start()
time.sleep(20)
world.stop()

"""
Explanation: Run
End of explanation
"""


