1

I am a 10th grade high school computer student looking for help with python audio. I'm not asking anyone to do any work for me, but I've reached an impasse.

I am trying to create a custom speech program using python (not through the use of GTTS or pyttsx). I am trying to create phonemes through formant speech synthesis.

I have tried using pyaudio and single frequencies and I have studied sine waves and wave forms, but I am still struggling to produce any phoneme.

All I can do is create beeps with different frequencies.

import pyaudio
import numpy as np

p = pyaudio.PyAudio()

volume = 0.5     # range [0.0, 1.0]
fs = 84100       # sampling rate, Hz, must be integer
duration = 1.0   # in seconds, may be float
f = 800.0        # sine frequency, Hz, may be float

# generate samples, note conversion to float32 array
samples = (np.sin(2*np.pi*np.arange(fs*duration)*f/fs)).astype(np.float32)

# for paFloat32 sample values must be in range [-1.0, 1.0]
stream = p.open(format=pyaudio.paFloat32,
                channels=1,
                rate=fs,
                output=True)


p2 = pyaudio.PyAudio()

volume2 = 0.5     # range [0.0, 1.0]
fs2 = 49100       # sampling rate, Hz, must be integer
duration2 = 1.0   # in seconds, may be float
f2 = 680.0        # sine frequency, Hz, may be float

# generate samples, note conversion to float32 array
samples2 = (np.sin(2*np.pi*np.arange(fs2*duration2)*f2/fs2)).astype(np.float32)

# for paFloat32 sample values must be in range [-1.0, 1.0]
stream2 = p2.open(format=pyaudio.paFloat32,
                channels=1,
                rate=fs2,
                output=True)

# play. May repeat with different volume values (if done interactively) 
stream2.write(volume2*samples2)

stream2.stop_stream()
stream2.close()

p2.terminate(


# play. May repeat with different volume values (if done interactively) 
stream.write(volume*samples)

stream.stop_stream()
stream.close()

p.terminate()

How can I produce phonemes through only using sample rate and frequency in python?

0 Answers0