I am trying to launch this simple gradio voice recording interface. It runs fine on Google Colab, but the same code acts differently from the command line and in Pycharm.
I am installing whisper with
pip install git+.git
I also install
ffmpeg-python
On the command line the execution hangs and once the process is killed, I get the output that I would have seen had it not been hanging as :
$ python test_audio_delay.py <--- hangs after this line until process is killed.
* Running on local URL: http://127.0.0.1:8000
* Running on public URL:
This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces ()
Keyboard interruption in main thread... closing server.
Killing tunnel 127.0.0.1:8000 <>
(.venv)
If I run it in PyCharm, the filename (which is the voice recording) is captured, but I still get an error indicating "file cannot be reached", and I use the `local URL'
See error below:
C:\Git\Git\Documents\Workspace\RAG01\.venv\Scripts\python.exe C:\Git\Git\Documents\Workspace\RAG01\test_audio_delay.py
* Running on local URL: http://127.0.0.1:8000
* Running on public URL:
This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces ()
Processing file: C:\Users\NaderAfshar\AppData\Local\Temp\gradio\4418c42db7d360241e0cde3c9dd706ef3ac72ad0fd5513f3bebb94f5936e4e75\audio.wav
...
...
File "C:\Program Files\Python311\Lib\subprocess.py", line 1538, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified
below see the simple code:
import gradio as gr
import whisper
import os
def transcribe_audio(audio_file):
if not os.path.exists(audio_file):
print(f"Cannot locate file: {audio_file}")
return "Error: Audio file not found!"
else:
print(f"Processing file: {audio_file}")
model = whisper.load_model("base")
result = model.transcribe(audio_file, fp16=False)
return result["text"]
def main():
audio_input = gr.Audio(sources=["microphone"], type="filepath"),
output_text = gr.Textbox(label="Transcription")
iface = gr.Interface(fn=transcribe_audio,
inputs=audio_input,
outputs=output_text,
title="Audio Transcription App"
)
iface.launch(
share=True,
debug=True,
server_port=8000,
prevent_thread_lock=True
)
if __name__ == '__main__':
main()
I am trying to launch this simple gradio voice recording interface. It runs fine on Google Colab, but the same code acts differently from the command line and in Pycharm.
I am installing whisper with
pip install git+https://github/openai/whisper.git
I also install
ffmpeg-python
On the command line the execution hangs and once the process is killed, I get the output that I would have seen had it not been hanging as :
$ python test_audio_delay.py <--- hangs after this line until process is killed.
* Running on local URL: http://127.0.0.1:8000
* Running on public URL: https://097932757b4f98b0b0.gradio.live
This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)
Keyboard interruption in main thread... closing server.
Killing tunnel 127.0.0.1:8000 <> https://097932757b4f98b0b0.gradio.live
(.venv)
If I run it in PyCharm, the filename (which is the voice recording) is captured, but I still get an error indicating "file cannot be reached", and I use the `local URL'
See error below:
C:\Git\Git\Documents\Workspace\RAG01\.venv\Scripts\python.exe C:\Git\Git\Documents\Workspace\RAG01\test_audio_delay.py
* Running on local URL: http://127.0.0.1:8000
* Running on public URL: https://820b9f762f181a269b.gradio.live
This share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)
Processing file: C:\Users\NaderAfshar\AppData\Local\Temp\gradio\4418c42db7d360241e0cde3c9dd706ef3ac72ad0fd5513f3bebb94f5936e4e75\audio.wav
...
...
File "C:\Program Files\Python311\Lib\subprocess.py", line 1538, in _execute_child
hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: [WinError 2] The system cannot find the file specified
below see the simple code:
import gradio as gr
import whisper
import os
def transcribe_audio(audio_file):
if not os.path.exists(audio_file):
print(f"Cannot locate file: {audio_file}")
return "Error: Audio file not found!"
else:
print(f"Processing file: {audio_file}")
model = whisper.load_model("base")
result = model.transcribe(audio_file, fp16=False)
return result["text"]
def main():
audio_input = gr.Audio(sources=["microphone"], type="filepath"),
output_text = gr.Textbox(label="Transcription")
iface = gr.Interface(fn=transcribe_audio,
inputs=audio_input,
outputs=output_text,
title="Audio Transcription App"
)
iface.launch(
share=True,
debug=True,
server_port=8000,
prevent_thread_lock=True
)
if __name__ == '__main__':
main()
Share
Improve this question
asked Mar 31 at 17:48
Nader AfsharNader Afshar
238 bronze badges
1
- I installed FFmpeg using Chocolate. This allowed the script to successfully run in PayCharm, but I am still unable to run it from the command line. The FFmpeg bin folder is added to system Path as well. When executing form the command line, there is no response until the process is killed at which time we get the normal output about the local and public URLs followed by killed process. – Nader Afshar Commented Apr 1 at 20:11
1 Answer
Reset to default 0The resolution turned out to be related to the use of Git Bash shell. Switching to a windows command shell solved the problem.