-
Create and activate a new environment :
conda create --name <env> python=3.8 && conda activate <env>
-
Install required libraries using the following command:
pip install -r requirements.txt
-
Bootstrap the model code and other models as pre requisites:
sh model_bootstrap.sh
-
Download models and update the right model paths in model_dict.json.
-
Start the server at port 50051:
python server.py
docker build -t speech_recognition_model_api .
sudo docker run --cpus=6 -m 20000m -itd -p <<host_port>>:50051 --name speech_recognition_model_api -v <<host_model_path>>/deployed_models:<<container_model_path>>/deployed_models/ -i -t speech_recognition_model_api
In python,
python examples/python/speech-recognition/main.py
gcloud api-gateway api-configs create CONFIG_ID \
--api=API_ID --project=PROJECT_ID \
--grpc-files=api_descriptor.pb,api_config.yaml
gcloud api-gateway gateways create GATEWAY_ID \
--api=API_ID --api-config=CONFIG_ID \
--location=GCP_REGION --project=PROJECT_ID
gcloud api-gateway gateways describe GATEWAY_ID \
--location=GCP_REGION --project=PROJECT_ID
{
"config":{
"language": {
"value":"hi"
},
"transcriptionFormat": "TRANSCRIPT",
"audioFormat": "WAV"
},
"audio":{
"audioUri": "https://codmento.com/ekstep/test/changed.wav"
}
}
The api, protobuf are taken from google folder from the below repo:
https://github.com/googleapis/googleapis
Generated stub files from .proto file, using the following command:
python3 -m grpc_tools.protoc \
--include_imports \
--include_source_info \
--proto_path=./proto \
./proto/google/api/http.proto \
./proto/google/api/annotations.proto \
./proto/google/protobuf/descriptor.proto \
-I ./proto \
--descriptor_set_out=./proto/api_descriptor.pb \
--python_out=./stub \
--grpc_python_out=./stub \
./proto/speech-recognition-open-api.proto
To run tests, use the following command:
py.test --grpc-fake-server --ignore=wav2letter --ignore=wav2vec-infer --ignore=kenlm
DOC: https://cloud.google.com/api-gateway/docs/get-started-cloud-run-grpc#before_you_begin
In case you get a error such as, ModuleNotFoundError: No module named 'speech_recognition_open_api_pb2', do the following:
Go to stub/speech_recognition_open_api_pb2_grpc.py file, and in the import section change
'import speech_recognition_open_api_pb2 as speech__recognition__open__api__pb2'
to
'import stub.speech_recognition_open_api_pb2 as speech__recognition__open__api__pb2'
Issue:
- AttributeError: Can't get attribute 'Wav2VecCtc' on <module 'main' from 'server.py'> Solution: Import Wav2VecCtc in file you are starting.