39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import requests
|
|
import difflib
|
|
import sys
|
|
|
|
# Usage: python test_vosk_transcription.py <audio_file> <reference_text>
|
|
|
|
API_URL = 'http://localhost:5000/transcribe'
|
|
|
|
|
|
def similarity(a, b):
|
|
return difflib.SequenceMatcher(None, a, b).ratio()
|
|
|
|
|
|
def main():
|
|
if len(sys.argv) != 3:
|
|
print("Usage: python test_vosk_transcription.py <audio_file> <reference_text>")
|
|
sys.exit(1)
|
|
audio_path = sys.argv[1]
|
|
reference_text = sys.argv[2]
|
|
with open(audio_path, 'rb') as f:
|
|
files = {'audio': f}
|
|
response = requests.post(API_URL, files=files)
|
|
if response.status_code != 200:
|
|
print(f"API error: {response.text}")
|
|
sys.exit(1)
|
|
transcription = response.json().get('transcription', '')
|
|
sim = similarity(transcription, reference_text)
|
|
print(f"Transcription: {transcription}")
|
|
print(f"Reference: {reference_text}")
|
|
print(f"Similarity: {sim:.2f}")
|
|
if sim > 0.2:
|
|
print("Test PASSED: Similarity above threshold.")
|
|
sys.exit(0)
|
|
else:
|
|
print("Test FAILED: Similarity below threshold.")
|
|
sys.exit(1)
|
|
|
|
if __name__ == '__main__':
|
|
main() |