Reputation: 21
I'm recording male voice, when I click playback button how to convert male voice in to female voice and play it in female voice. I refer some links I tried sound pool
to change voice by changing the float rate but I'm not getting female voice and change frequency for audio track.
Here is my code:
soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId,
int status) {
loaded = true;
}
});
soundID = soundPool.load(mFileName, 1);
AudioManager audioManager = (AudioManager) getSystemService(AUDIO_SERVICE);
float actualVolume = (float) audioManager
.getStreamVolume(AudioManager.STREAM_MUSIC);
float maxVolume = (float) audioManager
.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
float volume = actualVolume / maxVolume;
/* if (loaded) {
iv.setImageDrawable(getResources().getDrawable(R.drawable.palyrec));
soundPool.play(soundID, volume, volume, 1, 0, 1.8f);
Log.e("Test", "Played sound");
}*/
int streamID = -1;
do {
iv.setImageDrawable(getResources().getDrawable(R.drawable.palyrec));
streamID = soundPool.play(soundID, volume, volume, 1, 0, 1.7f);
Log.e("Test", "Played sound");
} while(streamID==0);
Changing frequency Code: Integer[] freqset = {11025, 16000, 22050, 44100};
File file = new File(Environment.getExternalStorageDirectory(), "test.pcm");
int shortSizeInBytes = Short.SIZE/Byte.SIZE;
int bufferSizeInBytes = (int)(file.length()/shortSizeInBytes);
short[] audioData = new short[bufferSizeInBytes];
try {
InputStream inputStream = new FileInputStream(file);
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream);
DataInputStream dataInputStream = new DataInputStream(bufferedInputStream);
int i = 0;
while(dataInputStream.available() > 0){
audioData[i] = dataInputStream.readShort();
i++;
}
dataInputStream.close();
int sampleFreq = (Integer)spFrequency.getSelectedItem();
AudioTrack audioTrack = new AudioTrack(
AudioManager.STREAM_MUSIC,
sampleFreq,
AudioFormat .CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
bufferSizeInBytes,
AudioTrack.MODE_STREAM);
audioTrack.play();
audioTrack.write(audioData, 0, bufferSizeInBytes);
How it is possible to convert to female voice in android ?
Upvotes: 1
Views: 6408
Reputation: 411
I believe there might be a misunderstanding on the term frequency: the sample rate frequency is not the same as the perceived pitch frequency.
Changing sample rate frequency will change both pitch and time, like an audio tape played faster (for those old enough to remember :-)).
Changing pitch frequency upwards will not make it sound faster, but you will rapidly notice the digital artefacts introduced (chipmunk voice).
Might sound a bit better when going downwards (like in Luka's video).
But, in both case, the pitch change you have to apply is quite drastic and will produce some weird side effects.
The closest would be looking at the results obtained by software specialized in harmonizing or tuning signing vocal tracks. These softs look at the formants and do not change them to change the pitch.
One of the most famous soft for this : http://www.celemony.com/en/melodyne/what-is-melodyne
I think that in this case, you might want to slightly change some formants of the voice (which contain some of the characteristics our brain uses to recognize someone's voice) and the overall pitch but independently.
Also note the formants are numbered (F0, F1, F2, F3, ...) and F1 and F2 allow us to tell the difference between the vowel sounds. http://home.cc.umanitoba.ca/~krussll/phonetics/acoustic/formants.html
As Merlevede mentioned, I believe a one size-fits-all algorithm is quite difficult to come up.
Afaict, there are no libraries on android doing this...
Upvotes: 2
Reputation: 1801
You need to work with the frequencies. According to:
http://en.wikipedia.org/wiki/Voice_frequency
and
http://www.axiomaudio.com/blog/audio-oddities-frequency-ranges-of-male-female-and-children%E2%80%99s-voices/
A male voice's frequency is 85 to 180 Hz while a female's 165 to 255 Hz. From this, if you simple increase the overall sound frequency, you might get a female-like voice.
The above will not get you a perfect result. To get a perfect result you need to research more. You can get this also by by trial and error. Get a male to say some words. Get a female to say some words. Now, compare the frequencies. Obviously, the frequency of each persons voice is different.
Finally check out this video: http://www.youtube.com/watch?v=hD0HAo2iHbE
Upvotes: 1