public inbox for gcc-rust@gcc.gnu.org
 help / color / mirror / Atom feed
* How I Built a Voice Imitator with Python Step-by-Step
@ 2024-01-03 10:56 Blue Writers
  0 siblings, 0 replies; only message in thread
From: Blue Writers @ 2024-01-03 10:56 UTC (permalink / raw)
  To: gcc-rust

[-- Attachment #1: Type: text/plain, Size: 5448 bytes --]

Hello, friend What’s up! In today’s article, we will build together a Voice Imitator with Python, pyttsx3, and SpeechRecognition libraries the project is short, simple, and beginner-friendly.



View image: (https://images.unsplash.com/photo-1555949963-ff9fe0c870eb?crop=entropy&cs=tinysrgb&fit=max&fm=jpg&ixid=M3w0ODM4NTF8MHwxfHNlYXJjaHw4fHwlMjBQWVRIT058ZW58MHx8fHwxNzA0MjEwNjM2fDA&ixlib=rb-4.0.3&q=80&w=1080&utm_source=beehiiv&utm_medium=referral)
Caption: Photo by Shahadat Rahman on Unsplash

# **Ready? Let’s get started!**

# **REQUIREMENT**

First of all, you need to install Python on your machine if you have Python on your device skip this

To install Python, visit the official Python website: [ _[https://www.python.org/downloads/](https://www.python.org/downloads/)_ ] and download it

**Done? Great!**

Now, install the library we will be using for this project

To install the library, type this command into your command prompt or terminal:

```
pip install SpeechRecognition
```

```
pip install pyttsx3
```

**SpeechRecognition**: To record the voice and turn it into a text

**pyttsx3**: when the voice returns to a text, the pyttsx3 turns the text into a voice

# **Coding Part**

# **STEP.1**

Import the libraries we’re going to use in our projects

Like this:

```
import speech_recognition as sr
import  pyttsx3
```

Why “as sr”: To make it short, For example, instead of writing `speech_recognition.Recognizer()`, you can write `sr.Recognizer()`

# **STEP.2**

```
rec = sr.Recognizer()
```

The line `rec = sr.Recognizer()` creates a new Recognizer object called `rec`.

# **STEP.3**

```
with sr.Microphone() as src:
    print("Say something...")
    audio = rec.listen(src)
    text = rec.recognize_google(audio)
```

`with sr.Microphone() as src:`: This line tells the computer to start listening to the microphone. The microphone is now called `src`.

`print("Say something...")`: This line tells the computer to print a message that says "Say something..." to the person using the program. This is a reminder for the person to speak into the microphone.

`audio = rec.listen(src)`: This line tells the computer to listen to the microphone for a while and store the recorded sound as `audio`.

`text = rec.recognize_google(audio)`: This line tells the computer to use Google Speech Recognition to convert the recorded sound (`audio`) into text. The text is stored as `text`.

# **STEP.4**

```
engine = pyttsx3.init()
```

This line tells the computer to activate the voice synthesizer, which is used to turn text into a voice.

# **STEP.5**

```
engine.say(text)
```

This line tells the computer to use the voice generator (`engine`) to read aloud the text (`text`) that the person just said. It's like pressing the "play" button on a recording device to listen to what the person just recorded.

# **STEP.6**

```
engine.runAndWait()
```

This line tells the computer to wait until the voice generator (`engine`) has finished reading aloud the text (`text`) before moving on to the next step. It's like waiting for the recording to finish playing before turning off the device.

# **STEP.7**

Run the program and say something

**NOTE**:

If the program doesn’t work try to do this

```
pip install setuptools
```

# **FULL CODE**

```
import speech_recognition as sr
import  pyttsx3

rec = sr.Recognizer()

with sr.Microphone() as src:
    print("Say something...")
    audio = rec.listen(src)
    text = rec.recognize_google(audio)

engine = pyttsx3.init()

engine.say(text)

engine.runAndWait()
```

**Ready to share your passion? Easily launch your newsletter **__**[with Beehiiv and reach a wider audience.](https://flight.beehiiv.net/v2/clicks/eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1cmwiOiJodHRwczovL2ZsaWdodC5iZWVoaWl2Lm5ldC92Mi9jbGlja3MvZXlKaGJHY2lPaUpJVXpJMU5pSXNJblI1Y0NJNklrcFhWQ0o5LmV5SjFjbXdpT2lKb2RIUndjem92TDNkM2R5NWlaV1ZvYVdsMkxtTnZiUzhfZG1saFBXSnNkV1VtZFhSdFgzTnZkWEpqWlQxaWJIVmxkM0pwZEdWeWN5NWlaV1ZvYVdsMkxtTnZiU1oxZEcxZmJXVmthWFZ0UFhKbFptVnljbUZzSm5WMGJWOWpZVzF3WVdsbmJqMXdlWFJvYjI0dGNISnZhbVZqZEMxbWIzSXRZbVZuYVc1dVpYSnpMV3hsZEMxekxXSjFhV3hrTFhOcGJYQnNaUzFqWVd4amRXeGhkRzl5SWl3aWNHOXpkRjlwWkNJNklqazNORGRqTURSa0xXSTBObUl0TkRReE55MWlZVEprTFdNME5ETTVaVEprTVRjek5TSXNJbkIxWW14cFkyRjBhVzl1WDJsa0lqb2lNakExWXpabE5ETXRZak0wWWkwMFl6VmhMV0V3T0dRdFpXTTJaRGM1TUdSbU1HTTVJaXdpZG1semFYUmZkRzlyWlc0aU9pSmtaRE5pWlRVME1TMHhObVU1TFRSbE1UTXRZbVl3TnkxaE5EWTRZVGc1WkRSa00yUWlMQ0pwWVhRaU9qRTNNRFF5TURnMk16Z3NJbWx6Y3lJNkltOXlZMmhwWkNKOS5pYnBtcjNsQ0duakdiTU1xVzVQUEtYaXRodndQSjZDM0U4a3AtWlRQUG04P3V0bV9zb3VyY2U9Ymx1ZXdyaXRlcnMuYmVlaGlpdi5jb20mdXRtX21lZGl1bT1yZWZlcnJhbCZ1dG1fY2FtcGFpZ249cHl0aG9uLXByb2plY3QtZm9yLWJlZ2lubmVycy1sZXQtcy1idWlsZC1pbnRlcm5ldC1zcGVlZC10ZXN0ZXIiLCJwb3N0X2lkIjoiZDMyZTU5NDUtNDNjYi00YmU4LTljODUtOTZiOWRhMzlmNzQyIiwicHVibGljYXRpb25faWQiOiIyMDVjNmU0My1iMzRiLTRjNWEtYTA4ZC1lYzZkNzkwZGYwYzkiLCJ2aXNpdF90b2tlbiI6ImRkM2JlNTQxLTE2ZTktNGUxMy1iZjA3LWE0NjhhODlkNGQzZCIsImlhdCI6MTcwNDIxMDcwNCwiaXNzIjoib3JjaGlkIn0.TZEiQdce35mrmFeE1TgU6wEdyx1-jpic_wLeK150neA)**__

_**Thanks for reading a have great day friend **_😍😍


———

You are reading a plain text version of this post. For the best experience, copy and paste this link in your browser to view the post online:
https://bluewriters.beehiiv.com/p/built-voice-imitator-python-stepbystep

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-03 10:56 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-03 10:56 How I Built a Voice Imitator with Python Step-by-Step Blue Writers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).