I have the following code outputting an audio sinus wave with Python:
import time
import numpy as np
import pyaudio
samples = (np.sin(2 * np.pi * np.arange(fs * duration) * f / fs)).astype(np.float32)
output_bytes = (volume * samples).tobytes()
stream = p.open(format=pyaudio.paFloat32,
channels=1,
rate=fs,
output=True)
#play. May repeat with different volume values (if done interactively)
start_time = time.time()
stream.write(output_bytes)
print("Played sound for {:.2f} seconds".format(time.time() - start_time))
stream.stop_stream()
stream.close()
p.terminate()
I want to modify samples to make the sound fade in and out at predefined length as marging or padding of the actual sound sinusoidal wave, to be able to generate valid auditive morse code that can be understood by an operator. How do I proceed? After having a fade, can I just concatenate the waves to a new sample to get he morse characters?
Should I map all values of sample with a function that goes from 0 to 1 for the first x values of the sample? How do I do this, what data type is sample?
Well I'm not used to do math anymore, new to python and don't know how to modify the function to generate a fading wave form with numpy.