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
938d677
master
1#pragma once 2#include <stdint.h> 3#include <assert.h> 4 5namespace Whisper 6{ 7enum struct eModelImplementation :uint32_t 8 { 9// GPGPU implementation based on Direct3D 11.0 compute shaders 10GPU = 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 14Hybrid = 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 18Reference = 3 , 19 }; 20 21// Timespan structure decomposed into fields 22struct sTimeSpanFields 23 { 24uint32_t days ; 25uint8_t hours ,minutes ,seconds ; 26uint32_t ticks ; 27 28sTimeSpanFields (uint64_t tt ) 29 { 30ticks = (uint32_t )(tt %10'000'000 ); 31tt /=10'000'000 ; 32seconds = (uint8_t )(tt %60 ); 33tt /=60 ; 34minutes = (uint8_t )(tt %60 ); 35tt /=60 ; 36hours = (uint8_t )(tt %24 ); 37tt /=24 ; 38days = (uint32_t )tt ; 39 } 40 }; 41 42// C++ equivalent of System.Timespan C# structure 43struct sTimeSpan 44 { 45// The value is expressed in 100-nanoseconds ticks: compatible with System.Timespan, FILETIME, and many other things 46uint64_t ticks ; 47 48operator sTimeSpanFields ()const 49 { 50return sTimeSpanFields {ticks }; 51 } 52void operator = (uint64_t tt ) 53 { 54ticks = tt ; 55 } 56void operator = (int64_t tt ) 57 { 58assert (tt >=0 ); 59ticks = (uint64_t )tt ; 60 } 61 }; 62 63// Start and end times of the segment or token, expressed in 100-nanosecond ticks 64struct sTimeInterval 65 { 66sTimeSpan begin ,end ; 67 }; 68 69// Segment data 70struct sSegment 71 { 72// Segment text, null-terminated, and probably UTF-8 encoded 73const char * text ; 74// Start and end times of the segment 75sTimeInterval time ; 76// These two integers define the slice of the tokens in this segment, in the array returned by iTranscribeResult.getTokens method 77uint32_t firstToken ,countTokens ; 78 }; 79 80enum eTokenFlags :uint32_t 81 { 82None = 0 , 83Special = 1 , 84 }; 85inline bool operator & (eTokenFlags a ,eTokenFlags b ) 86 { 87return 0 != ( (uint32_t )a & (uint32_t )b ); 88 } 89 90// Token data 91struct 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 96const char * text ; 97// Start and end times of the token 98sTimeInterval time ; 99// Probability of the token 100float probability ; 101// Probability of the timestamp token 102float probabilityTimestamp ; 103// Sum of probabilities of all timestamp tokens 104float ptsum ; 105// Voice length of the token 106float vlen ; 107// Token id 108int id ; 109eTokenFlags flags ; 110 }; 111 112struct sTranscribeLength 113 { 114uint32_t countSegments ,countTokens ; 115 }; 116 117enum struct eResultFlags :uint32_t 118 { 119None = 0 , 120// Return individual tokens in addition to the segments 121Tokens = 1 , 122// Return timestamps 123Timestamps = 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 128NewObject = 0x100 , 129 }; 130 131inline eResultFlags operator |(eResultFlags a ,eResultFlags b ) 132 { 133return (eResultFlags )( (uint32_t )a | (uint32_t )b ); 134 } 135 136inline bool operator & (eResultFlags a ,eResultFlags b ) 137 { 138return 0 != ( (uint32_t )a & (uint32_t )b ); 139 } 140 141// Output value for iContext.detectSpeaker method 142enum struct eSpeakerChannel :uint8_t 143 { 144Unsure = 0 , 145Left = 1 , 146Right = 2 , 147NoStereoData = 0xFF , 148 }; 149}