for i in range(0, 8):
            file = filename + "channel" + str(i) + ".wav"
            WAV_FILE = path.join(path.dirname(path.realpath(__file__)), file)

            with sr.WavFile(WAV_FILE) as source:
                audio = r.record(source)  # read the entire WAV file

            # recognize speech using Google Speech Recognition
            try:
                # for testing purposes, we're just using the default API key
                # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
                # instead of `r.recognize_google(audio)`
                testtext = r.recognize_google(audio)
                print("Google Speech Recognition for mic " + str(i) + "::::::::::" + str(testtext.encode('utf-8')))
                res = wer.wer(reftext, testtext)
                print('Word Error Rate: {0:.04f}'.format(res))
            except sr.UnknownValueError:
                print("Google Speech Recognition could not understand audio")
            except sr.RequestError as e:
                print("Could not request results from Google Speech Recognition service; {0}".format(e))

        WAV_FILE = path.join(path.dirname(path.realpath(__file__)), filename + "SD.wav")

        with sr.WavFile(WAV_FILE) as source:
            audio = r.record(source)  # read the entire WAV file

        # recognize speech using Google Speech Recognition
        try:
            # for testing purposes, we're just using the default API key
            # to use another API key, use `r.recognize_google(audio, key="GOOGLE_SPEECH_RECOGNITION_API_KEY")`
Beispiel #2
0
f1 = '/home/tyf/api/api_test/testdata/测试文书/传唤证/常玮平传唤通知.jpg_2018-08-15_15-37-23.txt'
f2 = '/home/tyf/api/api_test/testdata/测试文书/传唤证/恥松.txt'
# f1='E:\项目\\18.7.16东大项目\测试文书\'
# f1='E:\项目\\18.7.16东大项目\测试文书\拘留证\陈鸿志-黑社会.txt'
# f2='E:\项目\\18.7.16东大项目\测试文书\拘留证\据留.txt'
fref = codecs.open(f1, 'r', encoding='utf-8').readlines()
fpred = codecs.open(f2, 'r', encoding='utf-8').readlines()
fref = [s.strip() for s in fref]
fpred = [s.strip() for s in fpred]

fref = ''.join(fref)
fpred = ''.join(fpred)
# print(fref)
# print(fref[0])
ret = asr_wer.wer(fref, fpred, debug=True)
# print lcs(fref,fpred)
# fref= u' '.join([char for char in fref])
# fpred= u' '.join([char for char in fpred])
#
# ret = asr_wer.wer(fref,fpred, debug=True)

#fref=[u' '.join(list(s.strip().replace(u' ',u''))) for s in fref ]
#fpred=[u' '.join(list(s.strip().replace(u' ',u''))) for s in fpred ]
# err_numSub, err_numDel , err_numIns,total_char=0,0,0,0
#
# sentcount=0
#
# for r,p in zip(fref,fpred):
#     numSub, numDel , numIns,tchars=wer.wer(r,p)
#     err_numSub+=numSub