Jacky2305 commited on
Commit
9af9e2c
·
1 Parent(s): bc3399f

Fix parselmouth commands: use 'Change pitch' + 'Change formants' instead of 'Change gender'

Browse files
Files changed (1) hide show
  1. app_simple.py +6 -9
app_simple.py CHANGED
@@ -51,24 +51,21 @@ def convert_voice_simple(
51
  # Convert to parselmouth Sound
52
  sound = parselmouth.Sound(y, sampling_frequency=sr)
53
 
54
- # 1. Pitch shift using PSOLA
55
  if pitch_shift != 0:
56
- # Convert semitones to ratio
57
  pitch_ratio = 2 ** (pitch_shift / 12.0)
58
- # Use PSOLA for high-quality pitch shifting
59
- sound = call(sound, "Change gender", pitch_ratio, 1.0, 1.0, 1.0, 1.0)
60
 
61
- # 2. Formant shift
62
  if formant_shift != 0:
63
  formant_ratio = 2 ** (formant_shift / 12.0)
64
- # Change formants without changing pitch
65
- sound = call(sound, "Change gender", 1.0, formant_ratio, 1.0, 1.0, 1.0)
66
 
67
  # 3. Add breathiness (mix with noise)
68
  if breathiness > 0:
69
- # Generate breath noise
70
  noise = np.random.normal(0, breathiness * 0.1, len(sound.values[0]))
71
- # Apply noise mainly to unvoiced segments (simple approach)
72
  sound.values[0] = sound.values[0] * (1 - breathiness) + noise * breathiness
73
 
74
  # Get result
 
51
  # Convert to parselmouth Sound
52
  sound = parselmouth.Sound(y, sampling_frequency=sr)
53
 
54
+ # 1. Pitch shift using PSOLA (Change pitch command)
55
  if pitch_shift != 0:
 
56
  pitch_ratio = 2 ** (pitch_shift / 12.0)
57
+ # Change pitch: pitch_ratio, time_step, min_pitch, max_pitch
58
+ sound = call(sound, "Change pitch", pitch_ratio, 0.01, 50, 500)
59
 
60
+ # 2. Formant shift (Change formants command)
61
  if formant_shift != 0:
62
  formant_ratio = 2 ** (formant_shift / 12.0)
63
+ # Change formants: formant_ratio, new_pitch_median
64
+ sound = call(sound, "Change formants", formant_ratio, 1.0)
65
 
66
  # 3. Add breathiness (mix with noise)
67
  if breathiness > 0:
 
68
  noise = np.random.normal(0, breathiness * 0.1, len(sound.values[0]))
 
69
  sound.values[0] = sound.values[0] * (1 - breathiness) + noise * breathiness
70
 
71
  # Get result