I created this Python project to experiment with text-to-speech generation and audio processing.
The script works as a small voice effects studio. It converts user text into speech using installed system voices, then allows the user to apply different audio effects and export the final result as a WAV file.
The project was created to learn more about
:
- Text-to-speech engines
- Audio waveform manipulation
- Voice processing techniques
- Working with WAV files
- Python audio libraries
Features:
- Detects available system voices
- Allows selecting different TTS voices
- Converts text input into speech
- Applies multiple voice effects
- Exports processed audio into WAV format
- Automatically plays the final audio file
Available voice effects:
1. Robot voice
2. Cartoon voice
3. Low narrator voice
4. Deep cinematic voice
5. Electronic voice
6. Metallic robot effect
7. Room echo effect
8. High cartoon voice
9. AM/FM radio effect
10. Computer assistant style
Libraries used:
pyttsx3
- Offline text-to-speech engine using installed system voices
pydub
- Audio processing and effects
winsound
- WAV playback on Windows
tempfile / os
- Temporary file creation and cleanup
Installation:
pip install pyttsx3 pydub
Note:
FFmpeg may be required for additional pydub audio features.
This is a learning project focused on Python audio processing and experimenting with different voice styles.
Future improvements:
- More advanced audio filters
- Real-time voice processing
- GUI interface
- Saving custom effect presets
Feedback and suggestions are welcome.
Code:
import pyttsx3
from pydub import AudioSegment
import tempfile
import os
import winsound
# Initialize text-to-speech engine
engine = pyttsx3.init()
voices = engine.getProperty('voices')
print('Available system voices:')
for i, voice in enumerate(voices):
print(f'{i}: {voice.name} - {voice.languages}')
voice_index = int(input('Select voice number: '))
voice = voices[voice_index]
engine.setProperty('voice', voice.id)
text = input('Enter text for speech generation: ')
# Create temporary WAV file
with tempfile.NamedTemporaryFile(delete=False, suffix='.wav') as file:
temp_file = file.name
engine.save_to_file(text, temp_file)
engine.runAndWait()
# Load generated audio
audio = AudioSegment.from_wav(temp_file)
print('\nSelect voice effect:')
print('1 - Robot')
print('2 - Cartoon')
print('3 - Low narrator')
print('4 - Deep cinematic')
print('5 - Electronic')
print('6 - Metallic robot')
print('7 - Room echo')
print('8 - High cartoon')
print('9 - AM/FM radio')
print('10 - Computer assistant')
effect = input('Choose effect (1-10): ')
# Apply selected effect
if effect == '1':
audio = audio._spawn(
audio.raw_data,
overrides={'frame_rate': int(audio.frame_rate * 1.1)}
)
elif effect == '2':
audio = audio._spawn(
audio.raw_data,
overrides={'frame_rate': int(audio.frame_rate * 1.6)}
)
elif effect == '3':
audio = audio._spawn(
audio.raw_data,
overrides={'frame_rate': int(audio.frame_rate * 0.85)}
)
elif effect == '4':
audio = audio._spawn(
audio.raw_data,
overrides={'frame_rate': int(audio.frame_rate * 0.65)}
)
elif effect == '5':
audio = audio.high_pass_filter(800).low_pass_filter(3000)
elif effect == '6':
shifted = audio._spawn(
audio.raw_data,
overrides={'frame_rate': int(audio.frame_rate * 1.2)}
)
audio = audio.overlay(shifted, position=10)
elif effect == '7':
echo = audio - 10
audio = audio.overlay(echo, position=200)
elif effect == '8':
audio = audio._spawn(
audio.raw_data,
overrides={'frame_rate': int(audio.frame_rate * 2.0)}
)
elif effect == '9':
audio = audio.high_pass_filter(200)
audio = audio.low_pass_filter(3000)
audio = audio.apply_gain(-5)
elif effect == '10':
audio = audio._spawn(
audio.raw_data,
overrides={'frame_rate': int(audio.frame_rate * 1.05)}
)
echo = audio - 12
audio = audio.overlay(echo, position=120)
# Export final audio
output_file = 'voice_output.wav'
audio.export(output_file, format='wav')
print(f'\nAudio saved: {output_file}')
# Play generated audio
winsound.PlaySound(
output_file,
winsound.SND_FILENAME
)
# Remove temporary file
os.remove(temp_file)