call_transcript_kit 1.0.0
call_transcript_kit: ^1.0.0 copied to clipboard
A Dart package for parsing, segmenting, and analyzing call transcripts with spam detection and action item extraction.
Call Transcript Kit #
Call Transcript Kit is a pure Dart library designed for parsing, segmenting, and analyzing call transcripts. It parses raw verbose JSON responses from OpenAI Whisper into structured speaker turns by silence gaps. The package also extracts actionable follow-ups and calculates spam likelihood scores for incoming calls without relying on Flutter.
Installation #
Add this package to your pubspec.yaml under dependencies:
dependencies:
call_transcript_kit:
path: ./package
Then run:
dart pub get
Usage #
Here are usage examples for each class provided by the package.
1. SpeakerSegment #
Represents a single segment of a call transcript spoken by a specific speaker.
import 'package:call_transcript_kit/call_transcript_kit.dart';
void main() {
final segment = SpeakerSegment(
speakerLabel: 'Caller',
text: 'Hello, I need to cancel my subscription.',
startMs: 1200,
endMs: 4500,
sentiment: 'negative',
);
// Convert to JSON
final jsonMap = segment.toJson();
print(jsonMap);
// Parse from JSON
final parsed = SpeakerSegment.fromJson(jsonMap);
print(parsed.text);
}
2. TranscriptParser #
Groups words from Whisper's verbose JSON response into segments with silence gaps of more than 1.5 seconds, alternating speaker labels.
import 'package:call_transcript_kit/call_transcript_kit.dart';
void main() {
final parser = TranscriptParser();
final whisperJson = {
'words': [
{'word': 'Hello', 'start': 0.5, 'end': 0.9},
{'word': 'there', 'start': 1.0, 'end': 1.4},
{'word': 'Hi', 'start': 3.2, 'end': 3.5},
]
};
final List<SpeakerSegment> segments = parser.parseWhisperResponse(whisperJson);
for (final segment in segments) {
print('${segment.speakerLabel}: ${segment.text} (${segment.startMs}ms - ${segment.endMs}ms)');
}
}
3. SentimentAnalyzer #
Performs basic keyword matching to classify the sentiment of a text into positive, neutral, or negative.
import 'package:call_transcript_kit/call_transcript_kit.dart';
void main() {
const analyzer = SentimentAnalyzer();
final sentiment1 = analyzer.analyze('That sounds perfect, thank you so much!');
print(sentiment1); // Sentiment.positive
final sentiment2 = analyzer.analyze('I have a problem and the wrong item was sent.');
print(sentiment2); // Sentiment.negative
}
4. SpamClassifier #
Scores the call's spam likelihood based on duration, contact name presence, and suspicious transcript keywords.
import 'package:call_transcript_kit/call_transcript_kit.dart';
void main() {
const classifier = SpamClassifier();
final score = classifier.score(null, 5, 'KYC verify suspended urgent');
print('Spam Score: $score'); // 1.0
final isSpamCall = classifier.isSpam(score);
print('Is Spam: $isSpamCall'); // true
}
5. ActionItemExtractor #
Scans transcript speaker segments and extracts sentences that match action-oriented regex patterns.
import 'package:call_transcript_kit/call_transcript_kit.dart';
void main() {
const extractor = ActionItemExtractor();
final segments = [
SpeakerSegment(
speakerLabel: 'You',
text: 'I will send you the document tomorrow. Let me check the schedule.',
startMs: 1000,
endMs: 5000,
sentiment: 'neutral',
),
];
final actionItems = extractor.extract(segments);
for (final item in actionItems) {
print('Action Item: $item');
}
}
API Reference Table #
| Class | Purpose | Main Method |
|---|---|---|
SpeakerSegment |
Data class representing a speaker turn | toJson() / SpeakerSegment.fromJson() |
TranscriptParser |
Groups word-level timestamps into speaker segments | parseWhisperResponse(json) |
SentimentAnalyzer |
Computes sentiment (positive/neutral/negative) | analyze(text) |
SpamClassifier |
Evaluates the spam risk of a call | score(contactName, durationSeconds, transcriptText) |
ActionItemExtractor |
Identifies promises/tasks in transcript segments | extract(segments) |