错误:FileNotFoundError:[Errno 2]没有这样的文件或目录
问题描述:
我使用ubuntu和python运行Google云语音.首先,我将所有代码放在一个名为lu.py
的文件中:
I use ubuntu and python to run google cloud speech. First I put all the code in a file called lu.py
:
import io
import os
from google.cloud import speech
...
# The name of the audio file to transcribe
file_name = os.path.join(
os.path.dirname(__file__),
'resources',
'audio.raw')
# Loads the audio into memory
with io.open(file_name, 'rb') as audio_file:
content = audio_file.read()
audio = types.RecognitionAudio(content=content)
...
当我在终端中运行python lu.py
时,它说
When I ran python lu.py
in terminal, it said
FileNotFoundError: [Errno 2] No such file or directory: 'resources/audio.raw'
我对路径问题不熟悉,所以我不知道哪里出了问题.
I'm not familiar with the path problem, so I don't know where is wrong.
答
意味着在路径resources/[filename]
means file that contains the name audio.raw was not found in the path resources/[filename]
您可以在此注释下方的块中设置路径名称:
You can set the path name in the block below this comment:
# The name of the audio file to transcribe