Spaces:
Runtime error
Runtime error
Commit
·
6fd8e87
1
Parent(s):
a0a082a
Upload app.py
Browse files
app.py
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import random
|
2 |
+
from azure.cognitiveservices.speech import (
|
3 |
+
AudioDataStream,
|
4 |
+
SpeechConfig,
|
5 |
+
SpeechSynthesizer,
|
6 |
+
SpeechSynthesisOutputFormat,
|
7 |
+
)
|
8 |
+
|
9 |
+
# Subscription settings from Azure
|
10 |
+
# Region can be westeurope for example
|
11 |
+
subscription_key = "[AZURE_SPEECH_API_KEY]"
|
12 |
+
subscription_region = "[AZURE_SPEECH_API_REGION]"
|
13 |
+
|
14 |
+
# Input SSML file
|
15 |
+
# Open this file to change or fine-tune the pitch, pronunciation, speaking rate, volume, voice, language and more
|
16 |
+
# https://github.com/MicrosoftDocs/azure-docs/blob/master/articles/cognitive-services/Speech-Service/language-support.md#neural-voices
|
17 |
+
input_folder = "input/"
|
18 |
+
input_file = "ssml.xml"
|
19 |
+
|
20 |
+
# https://docs.microsoft.com/nl-nl/python/api/azure-cognitiveservices-speech/azure.cognitiveservices.speech.speechsynthesisoutputformat?view=azure-python
|
21 |
+
audio_format = "Riff24Khz16BitMonoPcm"
|
22 |
+
|
23 |
+
# Output folder and file
|
24 |
+
output_folder = "output/"
|
25 |
+
output_file = f"file-{random.randint(10000,99999)}.wav"
|
26 |
+
|
27 |
+
speech_config = SpeechConfig(subscription=subscription_key, region=subscription_region)
|
28 |
+
speech_config.set_speech_synthesis_output_format(
|
29 |
+
SpeechSynthesisOutputFormat[audio_format]
|
30 |
+
)
|
31 |
+
synthesizer = SpeechSynthesizer(speech_config=speech_config, audio_config=None)
|
32 |
+
|
33 |
+
input = open(f"{input_folder}{input_file}", "r").read()
|
34 |
+
result = synthesizer.speak_ssml_async(input).get()
|
35 |
+
|
36 |
+
stream = AudioDataStream(result)
|
37 |
+
stream.save_to_wav_file(f"{output_folder}{output_file}")
|