ChandimaPrabath commited on
Commit
c6169e1
β€’
1 Parent(s): c3553ac
Files changed (3) hide show
  1. README.md +2 -2
  2. app.py +44 -0
  3. requirements.txt +4 -0
README.md CHANGED
@@ -1,7 +1,7 @@
1
  ---
2
- title: Tts
3
  emoji: πŸƒ
4
- colorFrom: green
5
  colorTo: purple
6
  sdk: gradio
7
  sdk_version: 4.38.1
 
1
  ---
2
+ title: TTS
3
  emoji: πŸƒ
4
+ colorFrom: blue
5
  colorTo: purple
6
  sdk: gradio
7
  sdk_version: 4.38.1
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import wave
2
+ import numpy as np
3
+ from io import BytesIO
4
+ from flask import Flask, request, send_file
5
+ from flask_cors import CORS
6
+ from huggingface_hub import hf_hub_download
7
+ from piper import PiperVoice
8
+
9
+ app = Flask(__name__)
10
+ CORS(app)
11
+
12
+ def synthesize_speech(text, sentence_silence, length_scale):
13
+ model_path = hf_hub_download(repo_id="csukuangfj/vits-piper-en_US-lessac-medium", filename="en_US-lessac-medium.onnx")
14
+ config_path = hf_hub_download(repo_id="csukuangfj/vits-piper-en_US-lessac-medium", filename="en_US-lessac-medium.onnx.json")
15
+
16
+ voice = PiperVoice.load(model_path, config_path)
17
+
18
+ buffer = BytesIO()
19
+ with wave.open(buffer, 'wb') as wav_file:
20
+ wav_file.setframerate(voice.config.sample_rate)
21
+ wav_file.setsampwidth(2)
22
+ wav_file.setnchannels(1)
23
+ voice.synthesize(text, wav_file, sentence_silence=sentence_silence, length_scale=length_scale)
24
+
25
+ buffer.seek(0)
26
+ return buffer
27
+
28
+ @app.route('/')
29
+ def index():
30
+ return "Server is running"
31
+
32
+ @app.route('/tts', methods=['POST'])
33
+ def tts():
34
+ data = request.json
35
+ text = data.get('text', '')
36
+ sentence_silence = float(data.get('sentence_silence', 0.1))
37
+ length_scale = float(data.get('length_scale', 1.0))
38
+
39
+ audio_buffer = synthesize_speech(text, sentence_silence, length_scale)
40
+
41
+ return send_file(audio_buffer, mimetype="audio/wav", as_attachment=True, download_name="output.wav")
42
+
43
+ if __name__ == '__main__':
44
+ app.run(host='0.0.0.0', port=5000)
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ numpy==1.26.4
2
+ piper-tts==1.1.0
3
+ flask
4
+ Flask-Cors