python 英文语音转文字
时间: 2023-10-05 18:10:19 浏览: 42
There are many speech-to-text libraries and services available for Python, including Google Cloud Speech API, IBM Watson Speech to Text, and the Python Speech Recognition library. Here is an example using the Python Speech Recognition library:
```python
import speech_recognition as sr
# create a recognizer object
r = sr.Recognizer()
# open the audio file
with sr.AudioFile('audio.wav') as source:
# listen for the data (load audio to memory)
audio_data = r.record(source)
# recognize the speech in the audio data
text = r.recognize_google(audio_data)
# print the recognized text
print(text)
```
This code uses the `AudioFile` class from the Speech Recognition library to read in an audio file (`audio.wav`), and then uses the `recognize_google` method to transcribe the speech in the file into text. The resulting text is printed to the console.