Vergilerindir / BenimKendi

0 stars 0 forks source link

Main Program #1

Open Vergilerindir opened 1 year ago

Vergilerindir commented 1 year ago

Very easy to use ,just look at examples


import PIL
import numpy as np
import sys
import numpy.ma as ma
from scipy.io.wavfile import write
from pydub import AudioSegment
from pydub import effects
from pydub.effects import speedup
amplitude = np.iinfo(np.int16).max
def scale(arr,scalefact):
  B = np.zeros(scalefact*len(arr))
  for i in range(0,len(arr)):
    B[i*scalefact:(i+1)*scalefact] = arr[i]*np.ones(scalefact)
  return B
def pack(data,sampleRate):
  data[data > 100 ]= 200
  data[data < 100] = 255
  data[data == 200] = 0
  _data = scale(data,50)
  Samples = np.zeros(int(sampleRate/2))
  Samples[200:200+len(_data)] = _data
  b = np.zeros(2*len(Samples)-1)
  b[-len(Samples):] = Samples
  b[0:len(Samples)-1] = np.flip(Samples)[:-1]
  return b
def freqtosample(data,sampleRate):
  A = pack(data,sampleRate)
  A = np.fft.fftshift(A)
  #print("hello")
  #print(data)
  return np.fft.ifft(A)
def Auto(data,samplerate):
  samples = freqtosample(data,samplerate)
  samples = amplitude*samples/np.max(samples)
  return samples
def pouriton(daata,samplerate):
  A = np.zeros(1)
  for i in range(0,len(daata[0,:])):
    Z = Auto(daata[:,i],samplerate)
    A = np.append(A,Z)
  return A
def _write(data,nam,speedu=1):
  write("example.wav", 48000*2, np.real(data).astype(np.int16))
  src = "example.wav"
  dst = nam
  from pydub import AudioSegment
  from pydub import effects
  # convert wav to mp3                                                            
  sound = AudioSegment.from_wav(src)
  sound = speedup(sound,2*speedu,200*speedu)
  sound.export(dst, format="mp3")
def singleImage(si,dstname,speedu=1):
  im1 = Image.open(si).convert('L')
  im1 = im1.resize((100,100))
  I = np.asarray(im1)
  I = np.rot90(I)
  I = np.rot90(I)
  Q = pouriton(I,48000)
  _write(Q,dstname,speedu)
def stringarr(mstr,dstname,spe):
  Q = selfbecomeselves(mstr)
  _write(Q,dstname,spe)
def selfbecomeselves(vord):
  A = np.zeros(1)

  for i in vord:
    im = Image.open(i+".png").convert('L')
    I = np.asarray(im)
    I = np.rot90(I)
    I = np.rot90(I)
    I = np.fliplr(I)
    A = np.append(A,pouriton(I,48000))
  return A```