ICT - Intelligent Speech Technology

Pycharm

Learning Objectives

  1. Launch PyCharm and create new Python projects and files correctly.

  2. Use PyCharm terminal and pip commands to install required third-party libraries.

  3. Run Python ASR and TTS scripts and experience voice interaction functions.

  4. Modify key code parameters to achieve different ASR and TTS effects.

  5. Understand and apply basic Python syntax such as import, print, variable, comments, functions and parameters.

  6. (Extra) Combine ASR and TTS codes to implement a simple voice chat.

Activity 1 PyCharm Basic Operation

Launch PyCharm

Create a new Python project and sample py file.

Recognize project directory, code editing area.

Copy and run a simple hello world code

python
print('Hello World')

Change the code to run again

python
print('Anything that you like')

Activity 2 Library Installation & Environment Configuration

Open the built-in terminal window in PyCharm.

Input standard pip commands to install speechrecognition, pyaudio and edge-tts libraries.

shell
pip install speechrecognition pyaudio edge-tts

Check the installation feedback information to confirm successful configuration.

Activity 3 Run & Experience ASR & TTS Program

Copy and run official ASR sample code.

python
#ASR
import speech_recognition as sr
rec = sr.Recognizer()
mic = sr.Microphone()
print("Start to record")
mic.__enter__()
audio = rec.listen(mic)
txt = rec.recognize_google(audio, language='en-US')
print("Result ", txt)

Speak English sentences to test online voice recognition (ASR).

Check the text recognition results printed on the console.

Copy and run official TTS sample code.

python
#TTS
import edge_tts
import os
# You can change "Hello World!" to any text
txt = "Hello World!"
voice = "en-US-AriaNeural"
tts = edge_tts.Communicate(txt, voice)
path = "tts.mp3"
tts.save_sync(path)
os.startfile(path)

Listen to the automatic speech synthesis and playback (TTS).

Confirm the generated audio file is saved successfully.

Activity 4 Code Modification & Effect Debugging

Locate the TTS voice parameter and text content in the code.

Modify English voice types (male/female neural voice).

Voice Code

Language

Gender

en-US-AriaNeural

American English

Female

en-GB-RyanNeural

British English

Male

zh-CN-XiaoxiaoNeural

Mandarin Chinese

Female

zh-HK-HiuGaaiNeural

Cantonese

Female

zh-TW-HsiaoChenNeural

Taiwan Chinese

Female

Change custom text content for speech synthesis.

python
txt = "Anything you like"

Adjust audio file save name and path parameters.

python
path = 'anywhere.mp3'

Re-run the program and compare different TTS effects.

Modify the ASR code to recognise different language.

Language

Code

English

en-US

简体中文

zh-CN

粤语

zh-HK

Activity 5 Syntax Learning Test

  1. Mark core syntax lines including import, print and comments in code.

  2. Identify function structures and adjustable parameters in the script.

  3. Finish teacher’s syntax checking questions.

Syntax

Description

Code Example

import

Import external functional libraries

import speech_recognition as sr

comment

Add explanatory notes for code

# Import text-to-speech library

variable

Store data and status information

txt = "Hello World!"

function

Reusable code block to realize functions

sr.Recognizer(), rec.listen()

parameters

Data passed into functions

edge_tts.Communicate(txt, voice)

print

Output information to console

print("Start to record")

Single ChoiceQ1#1
[0/1]

Which library is used to realize voice-to-text function?

PythonSpeech Recognition
Single ChoiceQ2#2
[0/1]

What can the microphone object do in the code?

PythonSpeech Recognition
Single ChoiceQ3#3
[0/1]

What does the listen function mainly complete?

PythonSpeech Recognition
Single ChoiceQ4#4
[0/1]

Which parameter sets the recognition language of voice?

PythonSpeech Recognition
Single ChoiceQ5#5
[0/1]

Which library turns text into voice sound?

PythonTTS
Single ChoiceQ6#6
[0/1]

What file format is usually used to store voice audio?

AudioFile Format
Single ChoiceQ7#7
[0/1]

Which command installs Python third-party libraries?

PythonBasic Operation
Single ChoiceQ8#8
[0/1]

Which problem will broken string code bring?

PythonDebug
Single ChoiceQ9#9
[0/1]

What is the function of os.startfile()?

Pythonos Library
Single ChoiceQ10#10
[0/1]

Which basic grammar is used in this program?

PythonBasic Grammar

(Extra) Activity 6 Advanced Integrated Task

  1. Integrate two functional modules into one complete program.

  2. Realize the process of voice input → text recognition → automatic voice playback.

  3. Debug program errors to ensure stable one-click operation.

  4. Complete the full closed-loop voice interaction function.


AI Notes