Console/terminal demo of speech-to-text with the SpeechRecognition library, supporting Windows 11 and Ubuntu Linux 24.04. It transcribes a wav file (the default) or live microphone audio through the Google Web Speech API, in Traditional Chinese (zh-TW) by default or any other language via --language. One example recording ships in data/. An internet connection is required, and the microphone mode additionally needs PyAudio.

 

[Folder Structure]

  • CLAUDE.md / AGENT.md: program specification (identical content).
  • CHANGELOG.md: change log.
  • copyright.txt: copyright notice.
  • data/1.wav: the example recording (Mandarin, 44.1 kHz mono).
  • tool/tools.py: shared helpers.
  • src/: the demo, the launcher scripts and this document.
  • venv/: Python virtual environment, created by step 1.

There is no model/ folder, because the transcription is printed to the console.

 

[Prerequisites]

  • Operating system: Windows 11 or Ubuntu Linux 24.04.
  • Python 3 and pip.
  • An internet connection: the recognition itself runs on Google's Web Speech API.
  • The dependency (SpeechRecognition) is listed in src/requirements.txt and installed by step 1.
  • The microphone mode needs PyAudio. On Ubuntu, install portaudio19-dev first.
  • No GPU required.

[Instructions]

Step 1: create the virtual environment

Delete the old venv/, create a fresh one and install src/requirements.txt (SpeechRecognition); it aborts loudly if that fails. It then installs PyAudio best-effort, and a failure there only prints a warning, so the wav-file mode still works.

 

Windows 11: src\01_venv_create.bat

Ubuntu 24.04: sudo apt install portaudio19-dev

Ubuntu 24.04: bash src/01_venv_create.sh

 

Step 2: activate the virtual environment

Activate the venv you just created. On Linux, source it so the environment variables apply to the current shell.

 

Windows 11: src\02_venv_activate.bat

Ubuntu 24.04: source src/02_venv_activate.sh

 

Step 3: run the speech-to-text demo

Transcribe data/1.wav in zh-TW and print the text. Extra arguments are forwarded to the Python script.

 

Windows 11: src\03_speech_to_text.bat

Ubuntu 24.04: bash src/03_speech_to_text.sh

The microphone mode, or another file and language:

bash src/03_speech_to_text.sh --mic

bash src/03_speech_to_text.sh --wav path/to/audio.wav --language en-US

 

Step 4: clear the virtual environment (optional)

Delete the venv/ folder to free disk space when you no longer need it.

 

Windows 11: src\99_venv_clear.bat

Ubuntu 24.04: bash src/99_venv_clear.sh

 

[Python Entry Point]

  • src/speech_to_text.py: [--wav FILE] [--mic] [--language zh-TW].
  • --wav: the audio file to transcribe, default data/1.wav.
  • --mic: record from the microphone instead. The program measures the ambient noise first, and then you speak.
  • --language: the recognition language, zh-TW by default; en-US and other language codes also work.
  • A failed API request, for example with no internet, exits with a clear error message.

[Usage Notes]

  • The recognition runs on Google's Web Speech API, so an internet connection is always required.
  • PyAudio is only needed for --mic and is installed best-effort, so if it fails (missing PortAudio headers on Linux) the wav-file mode still works. Install portaudio19-dev and rerun step 1 to enable the microphone mode.

[References]

 

This SDK is built in AppForAI - AI Dev Tools.

 

Purchase license separately:  USD 600, permanent authorization, single APP authorization, single machine authorization, one-year activation, one-year download, one-year update, one-year email technical support.