whispermix 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.gitattributes ADDED
@@ -0,0 +1,2 @@
1
+ # Auto detect text files and perform LF normalization
2
+ * text=auto
package/README.md ADDED
@@ -0,0 +1,94 @@
1
+ # 🎙️ WhisperMix
2
+
3
+ WhisperMix is a flexible module that provides an interface for transcribing audio using OpenAI's Whisper model or Groq's Whisper Large v3 model.
4
+
5
+ ## 📦 Installation
6
+
7
+ ```bash
8
+ npm install whispermix
9
+ ```
10
+
11
+ ## ⚙️ Configuration
12
+
13
+ Before using WhisperMix, you need to set up your environment variables:
14
+
15
+ - For OpenAI's Whisper: Set `OPENAI_API_KEY` in your environment or `.env` file.
16
+ - For Groq's Whisper Large v3: Set `GROQ_API_KEY` in your environment or `.env` file.
17
+
18
+ ## 🚀 Usage
19
+
20
+ First, import the WhisperMix class:
21
+
22
+ ```javascript
23
+ const WhisperMix = require('whispermix');
24
+ ```
25
+
26
+ ### 🔧 Initializing WhisperMix
27
+
28
+ You can initialize WhisperMix with a specific model:
29
+
30
+ ```javascript
31
+ const whisper = new WhisperMix({ model: 'whisper-1' }); // For OpenAI's Whisper
32
+ // or
33
+ const whisper = new WhisperMix({ model: 'whisper-large-v3' }); // For Groq's Whisper Large v3
34
+ ```
35
+
36
+ ### 📄 Transcribing from a File
37
+
38
+ ```javascript
39
+ const filePath = 'path/to/your/audio/file.mp3';
40
+ whisper.fromVoiceFile(filePath)
41
+ .then(transcription => console.log(transcription))
42
+ .catch(error => console.error(error));
43
+ ```
44
+
45
+ ### 🌊 Transcribing from a Stream
46
+
47
+ ```javascript
48
+ const fs = require('fs');
49
+ const audioStream = fs.createReadStream('path/to/your/audio/file.mp3');
50
+
51
+ whisper.fromVoiceStream(audioStream)
52
+ .then(transcription => console.log(transcription))
53
+ .catch(error => console.error(error));
54
+ ```
55
+
56
+ ## 📚 API
57
+
58
+ ### `new WhisperMix(options)`
59
+
60
+ Creates a new WhisperMix instance.
61
+
62
+ - `options.model`: The model to use for transcription. Can be 'whisper-1' (OpenAI) or 'whisper-large-v3' (Groq).
63
+
64
+ ### `whisper.fromVoiceFile(filePath)`
65
+
66
+ Transcribes audio from a file.
67
+
68
+ - `filePath`: Path to the audio file.
69
+
70
+ Returns a Promise that resolves with the transcription text.
71
+
72
+ ### `whisper.fromVoiceStream(audioStream)`
73
+
74
+ Transcribes audio from a stream.
75
+
76
+ - `audioStream`: A readable stream of the audio data.
77
+
78
+ Returns a Promise that resolves with the transcription text.
79
+
80
+ ## ⚠️ Error Handling
81
+
82
+ WhisperMix throws errors for API request failures. Always wrap your calls in try-catch blocks or use `.catch()` with promises to handle potential errors.
83
+
84
+ ## 📄 License
85
+
86
+ The MIT License (MIT)
87
+
88
+ Copyright (c) Martin Clasen
89
+
90
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
91
+
92
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
93
+
94
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ ANTHROPIC_API_KEY=""
2
+ OPENAI_API_KEY=""
3
+ PPLX_API_KEY=""
4
+ GROQ_API_KEY=""
Binary file
package/demo/groq.js ADDED
@@ -0,0 +1,11 @@
1
+ const WhisperMix = require('../index.js')
2
+
3
+ const transcribe = new WhisperMix({ model: 'whisper-1' });
4
+
5
+
6
+ main(); async function main() {
7
+ const r = [];
8
+ r.push(transcribe.fromVoiceFile('./example.mp3'));
9
+ const x = await Promise.all(r).catch(console.log);
10
+ console.log(x)
11
+ }
package/index.js ADDED
@@ -0,0 +1,62 @@
1
+ const axios = require('axios');
2
+ const FormData = require('form-data');
3
+ const fs = require('fs');
4
+ require('dotenv').config();
5
+
6
+ class WhisperMix {
7
+ constructor(setup = { model: 'whisper-1' }) {
8
+ const config = {
9
+ 'whisper-1': {
10
+ url: 'https://api.openai.com/v1/audio/transcriptions',
11
+ code: 'OPENAI',
12
+ },
13
+ 'whisper-large-v3': {
14
+ url: 'https://api.groq.com/openai/v1/audio/transcriptions',
15
+ code: 'GROQ',
16
+ },
17
+ };
18
+
19
+ this.model = setup.model;
20
+ this.apiKey = process.env[config[this.model].code + '_API_KEY'];
21
+
22
+ Object.assign(this, setup)
23
+
24
+ this.apiUrl = config[this.model].url;
25
+
26
+ }
27
+
28
+ async fromVoiceFile(filePath) {
29
+ const formData = new FormData();
30
+ formData.append('file', fs.createReadStream(filePath));
31
+ formData.append('model', this.model);
32
+
33
+ return this._makeRequest(formData);
34
+ }
35
+
36
+ async fromVoiceStream(audioStream) {
37
+ return new Promise((resolve, reject) => {
38
+ const formData = new FormData();
39
+ formData.append('file', audioStream, { filename: 'audio.mp3' });
40
+ formData.append('model', this.model);
41
+
42
+ this._makeRequest(formData)
43
+ .then(resolve)
44
+ .catch(reject);
45
+ });
46
+ }
47
+
48
+ async _makeRequest(formData) {
49
+ try {
50
+ const response = await axios.post(this.apiUrl, formData, {
51
+ headers: {
52
+ ...formData.getHeaders(),
53
+ 'Authorization': `Bearer ${this.apiKey}`,
54
+ },
55
+ });
56
+ return response.data.text.trim();
57
+ } catch (error) {
58
+ throw error.response ? error.response.data : error.message;
59
+ }
60
+ }
61
+ }
62
+ module.exports = WhisperMix
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "whispermix",
3
+ "keywords": [
4
+ "whisper",
5
+ "openai",
6
+ "groq",
7
+ "transcription",
8
+ "speech-to-text",
9
+ "audio",
10
+ "voice",
11
+ "ai",
12
+ "machine-learning",
13
+ "nlp",
14
+ "natural-language-processing",
15
+ "audio-processing",
16
+ "voice-recognition",
17
+ "speech-recognition",
18
+ "api-wrapper",
19
+ "whisper-large-v3",
20
+ "whisper-1",
21
+ "streaming",
22
+ "file-processing",
23
+ "multilingual"
24
+ ],
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/clasen/WhisperMix.git"
28
+ },
29
+ "version": "1.0.0",
30
+ "description": "",
31
+ "main": "index.js",
32
+ "scripts": {
33
+ "test": "echo \"Error: no test specified\" && exit 1"
34
+ },
35
+ "author": "Martin Clasen",
36
+ "license": "MIT",
37
+ "bugs": {
38
+ "url": "https://github.com/clasen/ModelMix/issues"
39
+ },
40
+ "dependencies": {
41
+ "axios": "^1.7.2",
42
+ "dotenv": "^16.4.5",
43
+ "form-data": "^4.0.0"
44
+ }
45
+ }