Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4824

Python • Re: Writing generated audio as FLAC?

$
0
0
I think I have now worked out what to do.

Code:

#!/usr/bin/env python3import numpyimport soundfile as sfduration   = 0.1     # base in secondsamplitude  = 0.1     # range [0.0, 1.0]sampleRate = 44100   # integer sample rate, Hzfrequency  = 440.0   # float sine frequency, Hz# generate sine sample, with float32 array conversiondit = (numpy.sin(    numpy.arange(sampleRate * duration) * frequency / sampleRate \    * numpy.pi * 2 )).astype(numpy.float32)dah = numpy.concatenate((dit, dit, dit))dit = (amplitude * dit)dah = (amplitude * dah)gap = (0 * dit)r = numpy.concatenate((dit, gap, dah, gap, dit))sf.write('audio.flac', r, sampleRate)exit(0)
Hopefully more comprehension will come with time.

Statistics: Posted by tpyo kingg — Sat Feb 10, 2024 12:04 pm



Viewing all articles
Browse latest Browse all 4824

Trending Articles