You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Trying this library out to learn more about how audio streams work, and ran into an issue on my Win 10 machine.
I am attempting to send audio from my Electron app to two output devices: my computer speakers and my virtual audio cable. The following code appears to work for the most part:
import*asportAudiofrom'naudiodon';import*asfsfrom'fs';import*aswavfrom'wav';letwavFiles:fs.ReadStream[]=[];letwavReader;letheadPhones,virtualCable;letpaused=false;setupPortAudioDevices();exportfunctionsetupPortAudioDevices(){constfullDeviceList=portAudio.getDevices();constselectedDeviceList : portAudio.DeviceInfo[]=[];// Lookup the speakers and virtual cable devices.fullDeviceList.map((device)=>{if(device.name==="Speakers (VB-Audio CABLE-A)"||device.name==="Realtek Digital Output (Realtek"){selectedDeviceList.push(device);}});// Create the headphonesheadPhones=portAudio.AudioIO({outOptions: {channelCount: 1,sampleFormat: portAudio.SampleFormat16Bit,sampleRate: 48000,deviceId: selectedDeviceList[0].id,closeOnError: false}});// Create the virtual speakers (Crashes here on the second run)virtualCable=portAudio.AudioIO({outOptions: {channelCount: 1,sampleFormat: portAudio.SampleFormat16Bit,sampleRate: 48000,deviceId: selectedDeviceList[1].id,closeOnError: false}});console.log("PortAudio devices created.");}exportfunctionrouteAudio(file: string){if(wavReader){wavReader=undefined;}wavReader=newwav.Reader();wavReader.on('pause',(stuff)=>{console.log("Wave reader paused.");});wavReader.on('close',(stuff)=>{console.log("---- Wave reader CLOSED.");});console.log("Wave Reader created.");constnewWaveFile=fs.createReadStream(file);newWaveFile.on('data',(chunk)=>{console.log("data:",chunk);});newWaveFile.on('end',()=>{console.log('Wave ended.');});newWaveFile.on('error',(err)=>{console.error('Wave Error!');console.error(err);});newWaveFile.on('close',(err)=>{console.error('----------- Wave Closed!');// Re-open the now finished port audio devicessetupPortAudioDevices();});newWaveFile.on('pause',()=>{console.log("PAUSED the wav file");});// Pipe the WAV file through the reader to strip off the WAV header. newWaveFile.pipe(wavReader);// Pipe the stripped WAV to the two output devices wavReader.pipe(headPhones);wavReader.pipe(virtualCable);// Start the devicesheadPhones.start();virtualCable.start();}
Essentially when I run routeAudio(FILENAME) and pass it a WAV file it plays it out both devices to completion. However when the WAV file completes (on close) and I rerun the setupPortAudioDevices() function the headphones connect again properly but when attempting to connect the virtual cable device I get the following error:
I'm sure I'm doing something wrong here which is likely simple but I'm still rather new to this. Any assistance would be most welcome. Also, thank you for making such a cool library, it's greatly appreciated!
The text was updated successfully, but these errors were encountered:
Trying this library out to learn more about how audio streams work, and ran into an issue on my Win 10 machine.
I am attempting to send audio from my Electron app to two output devices: my computer speakers and my virtual audio cable. The following code appears to work for the most part:
Essentially when I run
routeAudio(FILENAME)
and pass it a WAV file it plays it out both devices to completion. However when the WAV file completes (on close) and I rerun thesetupPortAudioDevices()
function the headphones connect again properly but when attempting to connect the virtual cable device I get the following error:I'm sure I'm doing something wrong here which is likely simple but I'm still rather new to this. Any assistance would be most welcome. Also, thank you for making such a cool library, it's greatly appreciated!
The text was updated successfully, but these errors were encountered: