An application for transcribing voice to text using Whisper and generating structured queries with Gemini.
- Speech-to-Text - Transcribe uploaded audio files or record directly using your microphone
- Multiple Languages - Support for various languages with automatic language detection
- Configurable Models - Choose from different Whisper model sizes based on accuracy/speed needs
- Query Generation - Generate structured API queries from natural language using Gemini AI
- Image Context - Include images as reference for context-aware query generation
- Responsive UI - User-friendly interface built with Gradio
- REST API - Access all functionality through a RESTful API for integration with other services
- Python 3.8 or higher
- FFmpeg (for audio processing)
-
Clone the repository:
git clone https://github.com/yourusername/whisper-query-parser.git cd whisper-query-parser -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # Linux/Mac # OR venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
-
Set up environment variables:
- Copy the
.env.examplefile to.env
cp .env.example .env
- Edit the
.envfile and add your Google API key for Gemini:
GOOGLE_API_KEY=your_gemini_api_key_here- Get your API key from Google AI Studio
- Copy the
-
Start the application:
python app.py
-
Open your web browser and go to the URL displayed in the terminal (typically http://127.0.0.1:7860)
-
Using the interface:
- Select a Whisper model (tiny, base, small, medium, large)
- Choose a language or use auto-detect
- Upload a reference image if needed (for both tabs)
- Either upload an audio file or record with your microphone
- Click "Transcribe" to get the text result
- Click "Generate Structured Query" to create a JSON query
whisper-query-parser also provides a REST API that allows integration with other applications and services.
-
Start the API server:
python api_run.py
-
The API server will be available at http://localhost:8000 (configurable through arguments or environment variables)
-
API Endpoints:
GET /- Basic API informationPOST /transcribe- Transcribe an audio filePOST /generate-query- Generate a structured query from transcribed textPOST /process- Process audio file and optional image into a structured query
-
API Documentation:
- Interactive API documentation available at http://localhost:8000/docs
- ReDoc version available at http://localhost:8000/redoc
curl -X POST "http://localhost:8000/transcribe" \
-H "accept: application/json" \
-F "audio_file=@your_audio.wav" \
-F "language=en"Response:
{
"success": true,
"transcription": "Text transcribed from the audio file"
}curl -X POST "http://localhost:8000/generate-query" \
-H "accept: application/json" \
-F "transcription=Me gustaría una camiseta azul de manga corta" \
-F "image=@reference_image.jpg"Response:
{
"success": true,
"transcription": "Me gustaría una camiseta azul de manga corta",
"query": {
"items": [
{
"description": "camiseta azul manga corta",
"max_price": null
}
]
}
}curl -X POST "http://localhost:8000/process" \
-H "accept: application/json" \
-F "audio_file=@your_audio.wav" \
-F "image=@reference_image.jpg" \
-F "language=es"Response:
{
"success": true,
"transcription": "Me gustaría una camiseta azul de manga corta",
"query": {
"items": [
{
"description": "camiseta azul manga corta",
"max_price": null
}
]
}
}Para facilitar el despliegue en cualquier sistema, whisper-query-parser también está disponible como contenedor Docker.
-
Usando Docker Compose (recomendado):
docker-compose up -d
-
Usando Docker directamente:
docker build -t whisper-query-parser . docker run -d -p 8000:8000 -v $(pwd)/exports:/app/exports --name whisper-query-parser-api whisper-query-parser
Para más detalles sobre la configuración y uso con Docker, consulta DOCKER.md.
Speech: "Me gusta el conjunto pero quiero una camiseta azul en vez de rosa y me gustaría que fuera barata"
Generated Query:
{
"items": [
{
"product_type": "camiseta",
"color": "azul",
"price_range": {
"min": 0,
"max": 20
}
}
]
}Speech with Image: "El vestido es chulo pero no me convence, vamos a probar con unos vaqueros y una camiseta del mismo color"
Generated Query:
{
"items": [
{
"product_type": "vaqueros"
},
{
"product_type": "camiseta",
"color": "same as dress in image"
}
]
}- Query generation not working: Make sure you have set up the
GOOGLE_API_KEYenvironment variable with a valid API key. - Audio processing error: Check that FFmpeg is installed on your system.
- Memory issues with large models: Try using a smaller Whisper model or split large audio files into smaller segments.
- API connection issues: Check that you're connecting to the correct port and that the API server is running.
- OpenAI Whisper for speech-to-text capabilities
- Google Gemini for query generation
- Gradio for the user interface
- FastAPI for the API framework
app.py: Main application entry point with Gradio interfacerun.py: Launcher script with command-line options for the web interfaceapi.py: FastAPI implementation for the REST APIapi_run.py: Launcher script for the API serverutils/: Utility functions for audio processing and transcriptionaudio_processing.py: Functions for loading and processing audiotranscription.py: Functions for transcribing audio with Whisperquery_generation.py: Functions for generating structured queries
models/: Model configurationsconfigs/: Configuration fileswhisper_config.py: Configuration for Whisper models
tests/: Unit testsexamples/: Usage examples
Run the tests with pytest:
pytest-
Phase 1: Enhance the transcription features
- Add support for batch processing
- Implement caching for transcriptions
- Support for exporting results
-
Phase 2: Implement query generation
- Integrate with language models
- Process transcribed text into structured queries
- Extend the UI to display both transcription and queries
-
Phase 3: API and Services
- Optimize API performance
- Add authentication and rate limiting
- Develop client libraries for common languages
- OpenAI Whisper for the speech-to-text model
- Gradio for the web interface
- EnkrateiaLucca and xAlpharax for reference implementations