Does Replit Support Speech to Text with Pyaudio and Speech Recognition in Python?

Question: Does Replit Support Speech to Text with Pyaudio and Speech Recognition in Python?

I am making a game where the user says something, and if the thing that the user says is in a stored dictionary, then something happens. In order to do this, I need the Pyaudio Package, and the SpeechRecognition Package. I successfully installed the SpeechRecognition package in the replit shell with the following:

pip install speechrecognition

However, when I try to install pyaudio, I get the following error:


So I then tried to install it via the package manager, and got the same error.
Repl link
I have the following code:

import json
import speech_recognition as sr

# Create a recognizer object
r = sr.Recognizer()

# Record audio from the microphone
audio_data = r.record(source=sr.Microphone())

# Convert the audio to text
text = r.recognize_google(audio_data)

# Print the text to the console
# Load JSON data from the uploaded file
with open('hpspells.json') as json_file:
    spell_data = json.load(json_file)

# Prompt the user for input
user_input = input("Enter the spell name: ").lower()

# Search for the spell in the JSON data
found_spell = None
for spell in spell_data:
    if spell['Spell Name'].lower() == user_input:
        found_spell = spell

# Display spell stats if found
if found_spell:
    print("Spell Name:", found_spell['Spell Name'])
    print("Color:", found_spell['Color'])
    print("Damage:", found_spell['Damage'])
    print("Perk:", found_spell['Perk'])
    print("Chance of Damage On Contact:", found_spell['Chance of Damage on Contact'])
    print("Cooldown Time:", found_spell['Cooldown Time'])
    print("Cast Time:", found_spell['Cast Time'])
    print("Range:", found_spell['Range'])
    print("Required Accuracy:", found_spell['Accuracy'])
    print("Spell not found in the database.")


1 Like

I have doubts about the compatibility of pyaudio with Replit. However, it is worth noting that speechrecognition functions seamlessly in this environment.

1 Like

It likely wouldn’t work well because I’m assuming your attempting to record audio as if you were running a command line Python application on your own device, but it’s actually running on an entirely different device, and so audio recording becomes very difficult. I believe Replit did make a version of an audio package that does work, but either way, if you want to work with audio, I would recommend doing it on your own device or using HTML & JavaScript to do it in your browser.