错误:FileNotFoundError:[Errno 2]没有这样的文件或目录

时间:2018-07-30 04:19:19

标签: python file

我使用ubuntu和python运行Google云语音。首先,我将所有代码放入一个名为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时,它说

FileNotFoundError: [Errno 2] No such file or directory: 'resources/audio.raw'

我对路径问题不熟悉,所以我不知道哪里出了错。

1 个答案:

答案 0 :(得分:0)

在路径resources / [filename]中找不到包含名称audio.raw的文件

您可以在此注释下方的块中设置路径名称:

# The name of the audio file to transcribe