Azure Avatar TTS Update: Migrating from Azure TURN to Coturn

karthik Ganti
4 min readMar 19, 2024

--

Azure Avatar TTS

This article is an update to https://raokarthik83.medium.com/building-a-text-to-speech-avatar-app-with-reactjs-and-azure-tts-avatar-ai-c9d2da0e9f75

Microsoft is now retiring azure TURN services. Azure TTS avatar was using azure turn services for communication. Don’t worry we have other alternatives to use. In this article I will show how to setup open source TURN server on your own system.

We will be using custom turn server for Azure avatar TTS application.

😃 Well let’s begin.

WebRTC (Web Real-Time Communication) technology has revolutionized peer-to-peer communication on the web. However, to establish direct connections between peers, a protocol like STUN (Session Traversal Utilities for NAT) or TURN (Traversal Using Relays around NAT) is often needed, especially in scenarios involving NAT traversal or restrictive network environments. With Azure STUN/TURN server being retired, setting up your own TURN server using Coturn becomes a viable alternative.

Prerequisites:

  • An Ubuntu server (or any Linux distribution) where you’ll deploy Coturn.
  • Basic knowledge of Linux command line.
  • Access to configure firewall rules if necessary.

NOTE: I have deployed Coturn on AWS EC2 micro instance. I will also show the firewall security configurations.

Step1: Create an EC2 instance

Create micro instance on EC2 and put the following script in user data section:

#!/bin/bash

# Update package repositories
sudo apt-get -y update

# Install Coturn server
sudo apt-get install coturn -y

# Stop Coturn server
sudo service coturn stop

# Enable TURN server by adding configuration in /etc/default/coturn
echo 'TURNSERVER_ENABLED=1' | sudo tee -a /etc/default/coturn

# Backup existing turnserver.conf and create a new one
sudo mv /etc/turnserver.conf /etc/turnserver.conf.bak
sudo touch /etc/turnserver.conf

# Add configuration to the turnserver.conf file
sudo tee /etc/turnserver.conf > /dev/null <<EOF
# Listener IP address of relay server. Multiple listeners can be specified.
# If no IP(s) specified in the config file or in the command line options,
# then all IPv4 and IPv6 system IPs will be used for listening.
listening-ip=0.0.0.0
#listening-ip=10.207.21.238
#listening-ip=2607:f0d0:1002:51::4

min-port=49152
max-port=65535

# Uncomment to run TURN server in 'normal' 'moderate' verbose mode.
# By default the verbose mode is off.
verbose

# Uncomment to use fingerprints in the TURN messages.
# By default the fingerprints are off.
fingerprint

# Uncomment to use long-term credential mechanism.
# By default no credentials mechanism is used (any user allowed).
lt-cred-mech

# 'Static' user accounts are NOT dynamically checked by the turnserver process,
# so that they can NOT be changed while the turnserver is running.
user=user117:passworD@368
#user=username2:key2
# OR:
#user=username1:password1

# Log file location
log-file=/var/log/turn.log

# Option to redirect all log output into system log (syslog).
syslog

# Enable Web-admin support on https. By default it is Disabled.
# If it is enabled it also enables a http a simple static banner page
# with a small reminder that the admin page is available only on https.
web-admin

# Local system IP address to be used for Web-admin server endpoint. Default value is 127.0.0.1.
web-admin-ip=0.0.0.0

# Web-admin server port. Default is 8080.
EOF

# Restart Coturn server to apply the changes
sudo service coturn restart

If you want to the change the username and password you can update user=user117:passworD@368

AWS User Data

Step2: Update inbound rules

Now go to EC2 instance security group configuration and add following rules:

security group rules

Basically you need expose 3478 and 5439.

Now we are ready with TURN server. Yup that’s it 😄.

Step3: Start Azure TTS Demo App

Setup azure TTS Demo app

Go to config.js and update iceUrl, iceUsername and iceCredential


export const avatarAppConfig = {
cogSvcRegion : "westus2",
cogSvcSubKey : "YOUR_KEY",
voiceName : "en-US-JennyNeural",
avatarCharacter : "lisa",
avatarStyle : "casual-sitting",
avatarBackgroundColor : "#FFFFFFFF",
iceUrl : "stun:YOUR_AWS_INSTANCE_IP",
iceUsername : "user117",
iceCredential : "passworD@368"
}

Start the demo by running npm start on terminal.

Azure TTS Coturn

By migrating from Azure TTS Avatar AI to Coturn for peer to peer communication, you ensure the continued functionality and reliability of your Text-to-Speech Avatar app.

Explore more about Azure AI Text-to-Speech Avatar here and experiment with different settings and configurations to enhance your avatar’s capabilities. Happy coding!

--

--

karthik Ganti

Hi, I am karthik. Full Stack Developer | Web3 Expert | Micorservices Developer | Exploring Gen AI | ReactJS Developer. https://github.com/hacktronaut