Example #1
0
# Transpose maintaining spectral envelope
from scipy.io.wavfile import write
import scipy as sp
import pysms

audio_file = "voice.wav"

# analyse audio, also calculate the Discrete Cepstrum Envelope
frames, sms_header, snd_header = \
    pysms.analyze(audio_file, env_type=pysms.SMS_ENV_FBINS, env_order=80)

# Set modification parameters
mod_params = pysms.SMS_ModifyParams()
mod_params.maxFreq = 12000 # only calculate envelope up to 12 kHz
mod_params.doSinEnv = True # apply envelope to sinusoidal component
mod_params.doTranspose = True
mod_params.transpose = 4 # 4 semi-tones up

# apply modification to each frame
for frame in frames:
    pysms.sms_modify(frame, mod_params)

# Synthesis
output = pysms.synthesize(frames, sms_header)

# convert audio to int values
output /= output.max()
output = sp.asarray(output*32768, sp.int16)

# write output files
write("voice_transposed_env.wav", snd_header.iSamplingRate, output)
Example #2
0
# Copyright (c) 2010 John Glover, National University of Ireland, Maynooth
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
from scipy.io.wavfile import write
import numpy as np
import pysms

# Simple synthesis by analysis using libsms
input_file = 'flute.wav'
analysis_data, sms_header, snd_header = pysms.analyze(input_file)
audio_out = pysms.synthesize(analysis_data, sms_header)
write("synth.wav", sms_header.iSamplingRate,
      np.asarray(audio_out * 32768, dtype=np.int16))
Example #3
0
# Transpose maintaining spectral envelope
from scipy.io.wavfile import write
import scipy as sp
import pysms

audio_file = "voice.wav"

# analyse audio, also calculate the Discrete Cepstrum Envelope
frames, sms_header, snd_header = \
    pysms.analyze(audio_file, env_type=pysms.SMS_ENV_FBINS, env_order=80)

# Set modification parameters
mod_params = pysms.SMS_ModifyParams()
mod_params.maxFreq = 12000  # only calculate envelope up to 12 kHz
mod_params.doSinEnv = True  # apply envelope to sinusoidal component
mod_params.doTranspose = True
mod_params.transpose = 4  # 4 semi-tones up

# apply modification to each frame
for frame in frames:
    pysms.sms_modify(frame, mod_params)

# Synthesis
output = pysms.synthesize(frames, sms_header)

# convert audio to int values
output /= output.max()
output = sp.asarray(output * 32768, sp.int16)

# write output files
write("voice_transposed_env.wav", snd_header.iSamplingRate, output)
Example #4
0
# Copyright (c) 2010 John Glover, National University of Ireland, Maynooth
#  
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
from scipy.io.wavfile import write
import numpy as np
import pysms

# Simple synthesis by analysis using libsms
input_file = 'flute.wav'
analysis_data, sms_header, snd_header = pysms.analyze(input_file)
audio_out = pysms.synthesize(analysis_data, sms_header)
write("synth.wav", sms_header.iSamplingRate, np.asarray(audio_out*32768, dtype=np.int16))

Example #5
0
# The envelope_interp_factor only applies to the morph example
# if the envelope_interp_factor is 0, the original target envelope will be used (no morph)
# if it is 1, the original source envelope will be used
# any value in between will result in a linear interpolation between the two envelopes
envelope_interp_factor = 1

# In the transposition examples, transpose by this number of semitones
transposition = 4

# ----------------------------------------------------------------------------------------
# Impose a spectral envelope from one sound onto another set of sinudoidal tracks
# note: mod_params needs to be inititialized with sms_initModify to allocate the envelope array
# (not necessary in transpose examples)

# Analyze files
source_frames, source_sms_header, source_snd_header = analyze(
    source, env_type=SMS_ENV_FBINS, env_order=80)
target_frames, target_sms_header, target_snd_header = analyze(
    target, env_type=SMS_ENV_FBINS, env_order=80)

source_num_tracks = source_sms_header.nTracks
num_tracks = target_sms_header.nTracks
num_frames = min(len(source_frames), len(target_frames))

if num_tracks != source_num_tracks:
    print "Error: sound sources have a different number of tracks"
    exit()

# Set modification parameters
mod_params = SMS_ModifyParams()
sms_initModify(source_sms_header, mod_params)
mod_params.doSinEnv = True
Example #6
0
from scipy.io.wavfile import write
import scipy as sp
import pysms

# Have to analyze source again for now, should really be a way to copy/clone frames
audio_file = "voice.wav"
frames, sms_header, snd_header = pysms.analyze(audio_file)

# Set modification parameters
mod_params = pysms.SMS_ModifyParams()
mod_params.doTranspose = True
mod_params.transpose = 4 # 4 semi-tones up

# apply modification to each frame
for frame in frames:
    pysms.sms_modify(frame, mod_params)

# Synthesis
output = pysms.synthesize(frames, sms_header)

# convert audio to int values
output /= output.max()
output = sp.asarray(output*32768, sp.int16)

# write output files
write("voice_transposed.wav", snd_header.iSamplingRate, output)
Example #7
0
from scipy.io.wavfile import write
import scipy as sp
import pysms

# Have to analyze source again for now, should really be a way to copy/clone frames
audio_file = "voice.wav"
frames, sms_header, snd_header = pysms.analyze(audio_file)

# Set modification parameters
mod_params = pysms.SMS_ModifyParams()
mod_params.doTranspose = True
mod_params.transpose = 4  # 4 semi-tones up

# apply modification to each frame
for frame in frames:
    pysms.sms_modify(frame, mod_params)

# Synthesis
output = pysms.synthesize(frames, sms_header)

# convert audio to int values
output /= output.max()
output = sp.asarray(output * 32768, sp.int16)

# write output files
write("voice_transposed.wav", snd_header.iSamplingRate, output)
Example #8
0
# The envelope_interp_factor only applies to the morph example
# if the envelope_interp_factor is 0, the original target envelope will be used (no morph)
# if it is 1, the original source envelope will be used
# any value in between will result in a linear interpolation between the two envelopes
envelope_interp_factor = 1

# In the transposition examples, transpose by this number of semitones
transposition = 4

# ----------------------------------------------------------------------------------------
# Impose a spectral envelope from one sound onto another set of sinudoidal tracks
# note: mod_params needs to be inititialized with sms_initModify to allocate the envelope array
# (not necessary in transpose examples)

# Analyze files
source_frames, source_sms_header, source_snd_header = analyze(source, env_type=SMS_ENV_FBINS, env_order=80)
target_frames, target_sms_header, target_snd_header = analyze(target, env_type=SMS_ENV_FBINS, env_order=80)

source_num_tracks = source_sms_header.nTracks
num_tracks = target_sms_header.nTracks
num_frames = min(len(source_frames), len(target_frames))

if num_tracks != source_num_tracks:
    print "Error: sound sources have a different number of tracks"
    exit()

# Set modification parameters
mod_params = SMS_ModifyParams()
sms_initModify(source_sms_header, mod_params)
mod_params.doSinEnv = True 
mod_params.sinEnvInterp = envelope_interp_factor