Upload files to "test_examples/VoiceToSpeech"
This commit is contained in:
		
							
								
								
									
										11
									
								
								test_examples/VoiceToSpeech/index.html
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								test_examples/VoiceToSpeech/index.html
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,11 @@ | ||||
| <!DOCTYPE html> | ||||
| <html> | ||||
| <head> | ||||
|     <title>Audio zu Text</title> | ||||
| </head> | ||||
| <body> | ||||
|     <input type="file" accept="audio/*" id="audioFileInput"> | ||||
|     <div id="transcriptionResult"></div> | ||||
|     <script src="jav.js"></script> | ||||
| </body> | ||||
| </html> | ||||
							
								
								
									
										29
									
								
								test_examples/VoiceToSpeech/jav.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										29
									
								
								test_examples/VoiceToSpeech/jav.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,29 @@ | ||||
| const audioFileInput = document.getElementById('audioFileInput'); | ||||
| const transcriptionResult = document.getElementById('transcriptionResult'); | ||||
|  | ||||
| audioFileInput.addEventListener('change', () => { | ||||
|     const audioFile = audioFileInput.files[0]; | ||||
|  | ||||
|     if (!audioFile) { | ||||
|         transcriptionResult.textContent = "Bitte wählen Sie eine Audiodatei aus."; | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     // FormData erstellen, um die Datei an den Server zu senden | ||||
|     const formData = new FormData(); | ||||
|     formData.append('audioFile', audioFile); | ||||
|  | ||||
|     // HTTP POST-Anfrage an den Server senden | ||||
|     fetch('http://localhost:3000/upload', { | ||||
|         method: 'POST', | ||||
|         body: formData, | ||||
|     }) | ||||
|     .then(response => response.text()) | ||||
|     .then(result => { | ||||
|         transcriptionResult.textContent = result; | ||||
|     }) | ||||
|     .catch(error => { | ||||
|         transcriptionResult.textContent = "Fehler beim Transkribieren der Audiodatei."; | ||||
|         console.error(error); | ||||
|     }); | ||||
| }); | ||||
							
								
								
									
										1856
									
								
								test_examples/VoiceToSpeech/package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
							
						
						
									
										1856
									
								
								test_examples/VoiceToSpeech/package-lock.json
									
									
									
										generated
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										10
									
								
								test_examples/VoiceToSpeech/package.json
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										10
									
								
								test_examples/VoiceToSpeech/package.json
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,10 @@ | ||||
| { | ||||
|   "dependencies": { | ||||
|     "@google-cloud/speech": "^6.0.2", | ||||
|     "child_process": "^1.0.2", | ||||
|     "cors": "^2.8.5", | ||||
|     "express": "^4.18.2", | ||||
|     "fs": "^0.0.1-security", | ||||
|     "multer": "^1.4.5-lts.1" | ||||
|   } | ||||
| } | ||||
							
								
								
									
										38
									
								
								test_examples/VoiceToSpeech/server.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								test_examples/VoiceToSpeech/server.js
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| const express = require('express'); | ||||
| const multer = require('multer'); | ||||
| const cors = require('cors'); | ||||
| const app = express(); | ||||
| const port = 3000; | ||||
| const { exec } = require('child_process'); | ||||
| const fs = require('fs'); | ||||
|  | ||||
| app.use(cors()); | ||||
|  | ||||
| app.use(express.static('public')); | ||||
|  | ||||
| const storage = multer.memoryStorage(); | ||||
| const upload = multer({ storage: storage }); | ||||
|  | ||||
| app.post('/upload', upload.single('audioFile'), (req, res) => { | ||||
|     if (!req.file) { | ||||
|         return res.status(400).send("Keine Audiodatei hochgeladen."); | ||||
|     } | ||||
|  | ||||
|     // Speichern Sie die Audiodatei vorübergehend | ||||
|     const audioFilePath = 'temp.wav'; | ||||
|     fs.writeFileSync(audioFilePath, req.file.buffer); | ||||
|  | ||||
|     // Verwenden Sie pocketsphinx für die Transkription | ||||
|     exec(`pocketsphinx_continuous -infile ${audioFilePath}`, (error, stdout, stderr) => { | ||||
|         if (error) { | ||||
|             console.error('Fehler bei der Transkription:', error); | ||||
|             res.status(500).send('Fehler bei der Transkription'); | ||||
|         } else { | ||||
|             res.send(stdout); | ||||
|         } | ||||
|     }); | ||||
| }); | ||||
|  | ||||
| app.listen(port, () => { | ||||
|     console.log(`Server läuft auf Port ${port}`); | ||||
| }); | ||||
							
								
								
									
										
											BIN
										
									
								
								test_examples/VoiceToSpeech/temp.wav
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								test_examples/VoiceToSpeech/temp.wav
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
		Reference in New Issue
	
	Block a user