WebSpeechRecognition is a Python library that helps turn speech into text in real time. It uses the Selenium WebDriver and the HTML5 Web Speech API. This tool is built to work with Chrome WebDriver and is easy to use for speech recognition tasks.
To install WebSpeechRecognition, you can use pip:
pip install WebSpeechRecognition
To start using WebSpeechRecognition, initialize the SpeechRecognition
class with the path to your ChromeDriver executable and the language code:
from WebSpeechRecognition import SpeechRecognition
recognizer = SpeechRecognition("path/to/chromedriver", language="en-US")
recognizer.Init()
To start listening and transcribing speech, use the Listen
method. This method returns the transcribed text:
text = recognizer.Listen(print_allowed=True)
print(f"You said: {text}")
Once you are done, use the Quit
method to close the ChromeDriver instance:
recognizer.Quit()
Here is a complete example:
from WebSpeechRecognition import SpeechRecognition
recognizer = SpeechRecognition("path/to/chromedriver", language="en-US")
recognizer.Init()
while True:
try:
text = recognizer.Listen(print_allowed=True)
print(f"You said: {text}")
except KeyboardInterrupt:
recognizer.Quit()
break
SpeechRecognition(driver_path, language)
driver_path
: The path to the Chrome WebDriver file.language
: The language code for recognition (default: "en-US").Init()
Sets up the WebDriver with options for speech recognition.
Listen(print_allowed=False)
Starts listening and returns the text it hears.
print_allowed
: If True, prints recognized text to the console.Quit()
Stops the WebDriver and closes everything.
We welcome contributions! If you find a bug or have an idea for a new feature, feel free to open an issue or a pull request on our GitHub repository.
Want to help improve SpeechRecognition? Here's how:
git checkout -b feature-branch
).git commit -m 'Add feature'
).git push origin feature-branch
).This project uses the MIT License. See the LICENSE
file for details.
Have questions or suggestions? Contact us: