我正在尝试从 WAV 文件返回索引位置。
如果在大海捞针中找到针内容,那么我需要返回大海捞针中针的索引位置。
haystack = open("haystack.wav",'r').read()
needle = open("needle.wav",'r').read()
print(haystack.index(needle[:46]));
我收到一个错误:
Traceback (most recent call last):
File "test.py", line 1, in <module>
haystack = open("haystack.wav",'r').read()
File "C:\Python33\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 5: character maps to <undefined>
当我在 PHP 中执行此操作时,它可以工作:
$needle = file_get_contents("needle.wav", false, null, 46);
$haystack = file_get_contents("haystack.wav");
echo strpos($haystack,$needle);