LTSpice bad wavefile format after importing audio file

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
Importing audio into LTspice

I have a problem with importing recorded guitar in LTSpice AC voltage source. What I need do to fix it?

I've attached a simple LTspice circuit to demonstrate how to import, export and manipulate audio in LTspice.

Unzip the attached folder somewhere convenient. Copy an audio file into the folder. This must be a .wav file, preferably stereo. Rename this file demo.wav. LTspice cannot import compressed format audio such as .mp3 files.

Open ImportingAudioDemo.asc in LTspice. When you run this, it will read demo.wav and output the first 20 seconds of it as a file called output.wav. I have specified in the .WAVE command that this should be a 16-bit file with a sampling rate of 44.1 kHz (=CD quality).

This circuit doesn't do very much to the imported demo.wav audio except adjust its volume with the dual potentiometer VR1. Set the volume of the output with the parameter VOL in the range 0-1. Load output.wav into your media player to hear it.

There are more details in the help file. Search for "wav". The page headed ".WAVE" concerns writing .wav files, while the page "V. Voltage Source" details how to import a .wav file ( in the last few paragraphs).

View attachment Import Audio.zip
 
I had the same problem when using wav files exported from Logic (must have had some metadata added). I wrote a little python script to strip the metadata from a wav (just replace guitar.wav and guitar_new.wav with the input and output filenames):


Code:
from scipy.io import wavfile
samplerate, data = wavfile.read('guitar.wav')
wavfile.write('guitar_new.wav', samplerate, data[:, 0])  # only take left channel
 
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.