yum-archive/TaSTT-Whisper

High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model

git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper

KonstantinComments938d677

master
3.6 KiB149 linesraw
1#pragma once
2#include <stdint.h>
3#include <assert.h>
4
5namespace Whisper
6{
7	enum struct eModelImplementation : uint32_t
8	{
9		// GPGPU implementation based on Direct3D 11.0 compute shaders
10		GPU = 1,
11
12		// A hybrid implementation which uses DirectCompute for encode, and decodes on CPU
13		// Not implemented in the published builds of the DLL. To enable, change BUILD_HYBRID_VERSION macro to 1
14		Hybrid = 2,
15
16		// A reference implementation which uses the original GGML CPU-running code
17		// Not implemented in the published builds of the DLL. To enable, change BUILD_BOTH_VERSIONS macro to 1
18		Reference = 3,
19	};
20
21	// Timespan structure decomposed into fields
22	struct sTimeSpanFields
23	{
24		uint32_t days;
25		uint8_t hours, minutes, seconds;
26		uint32_t ticks;
27
28		sTimeSpanFields( uint64_t tt )
29		{
30			ticks = (uint32_t)( tt % 10'000'000 );
31			tt /= 10'000'000;
32			seconds = (uint8_t)( tt % 60 );
33			tt /= 60;
34			minutes = (uint8_t)( tt % 60 );
35			tt /= 60;
36			hours = (uint8_t)( tt % 24 );
37			tt /= 24;
38			days = (uint32_t)tt;
39		}
40	};
41
42	// C++ equivalent of System.Timespan C# structure
43	struct sTimeSpan
44	{
45		// The value is expressed in 100-nanoseconds ticks: compatible with System.Timespan, FILETIME, and many other things
46		uint64_t ticks;
47
48		operator sTimeSpanFields() const
49		{
50			return sTimeSpanFields{ ticks };
51		}
52		void operator=( uint64_t tt )
53		{
54			ticks = tt;
55		}
56		void operator=( int64_t tt )
57		{
58			assert( tt >= 0 );
59			ticks = (uint64_t)tt;
60		}
61	};
62
63	// Start and end times of the segment or token, expressed in 100-nanosecond ticks
64	struct sTimeInterval
65	{
66		sTimeSpan begin, end;
67	};
68
69	// Segment data
70	struct sSegment
71	{
72		// Segment text, null-terminated, and probably UTF-8 encoded
73		const char* text;
74		// Start and end times of the segment
75		sTimeInterval time;
76		// These two integers define the slice of the tokens in this segment, in the array returned by iTranscribeResult.getTokens method
77		uint32_t firstToken, countTokens;
78	};
79
80	enum eTokenFlags : uint32_t
81	{
82		None = 0,
83		Special = 1,
84	};
85	inline bool operator &( eTokenFlags a, eTokenFlags b )
86	{
87		return 0 != ( (uint32_t)a & (uint32_t)b );
88	}
89
90	// Token data
91	struct sToken
92	{
93		// Token text, null-terminated, and usually UTF-8 encoded.
94		// I think for Chinese language the models sometimes outputs invalid UTF8 strings here, Unicode code points can be split between adjacent tokens in the same segment
95		// More info: https://github.com/ggerganov/whisper.cpp/issues/399
96		const char* text;
97		// Start and end times of the token
98		sTimeInterval time;
99		// Probability of the token
100		float probability;
101		// Probability of the timestamp token
102		float probabilityTimestamp;
103		// Sum of probabilities of all timestamp tokens
104		float ptsum;
105		// Voice length of the token
106		float vlen;
107		// Token id
108		int id;
109		eTokenFlags flags;
110	};
111
112	struct sTranscribeLength
113	{
114		uint32_t countSegments, countTokens;
115	};
116
117	enum struct eResultFlags : uint32_t
118	{
119		None = 0,
120		// Return individual tokens in addition to the segments
121		Tokens = 1,
122		// Return timestamps
123		Timestamps = 2,
124
125		// Create a new COM object for the results.
126		// Without this flag, the context returns a pointer to the COM object stored in the context.
127		// The content of that object is replaced every time you call iContext.getResults method
128		NewObject = 0x100,
129	};
130
131	inline eResultFlags operator |( eResultFlags a, eResultFlags b )
132	{
133		return (eResultFlags)( (uint32_t)a | (uint32_t)b );
134	}
135
136	inline bool operator &( eResultFlags a, eResultFlags b )
137	{
138		return 0 != ( (uint32_t)a & (uint32_t)b );
139	}
140
141	// Output value for iContext.detectSpeaker method
142	enum struct eSpeakerChannel : uint8_t
143	{
144		Unsure = 0,
145		Left = 1,
146		Right = 2,
147		NoStereoData = 0xFF,
148	};
149}