Birden fazla ses dosyasını tek bir ses dosyasında birleştirebilir ve istediğiniz biçime dönüştürebilirsiniz. Bu konu, ses birleştirme için kullanılan parametreleri açıklar ve örnekler sunar.
Kullanım senaryoları
Müzik yapımı ve prodüksiyon: Müzisyenler ve yapımcılar, eksiksiz bir şarkı oluşturmak amacıyla ayrı ayrı kaydedilen enstrüman ve vokal parçalarını sıklıkla birleştirir.
Sesli kitap ve sesli içerik üretimi: Sesli kitap üretiminde, anlatılan içeriğin bölümler halinde kesintisiz sunulmasını sağlamak için ses kayıtları birleştirilir.
Film ve televizyon post prodüksiyonu: Post prodüksiyon aşamasında ses editörleri, diyalogları, anlatımı, ortam ses efektlerini ve arka plan müziğini görsellerle uyumlu hale getirmek üzere birleştirir.
Sosyal medya içeriği oluşturma: Kısa video platformundaki kullanıcılar, içeriklerini daha etkileyici kılmak için ses efektlerini, dış ses kayıtlarını ve arka plan müziklerini bir araya getirir.
Kullanım notları
Ses birleştirme işlemi yalnızca eşzamansız işleme (x-oss-async-process yöntemi kullanılarak) destekler.
Ses birleştirme işlemini gerçekleştirmeden önce bir IMM projesi bağlamanız gerekir. Konsolda veya API kullanarak proje bağlama talimatları için bkz. hızlı başlangıç ve OSS paketi bağlama.
Anonim erişim reddedilir.
Bu özelliği kullanmak için gerekli izinlere sahip olmanız gerekir. Daha fazla bilgi için bkz. izinler.
Varsayılan örnekleme hızı veya ses kanalı sayısının kullanılması, hedef ses kapsayıcı biçimiyle oluşan uyumluluk sorunları nedeniyle birleştirmenin başarısız olmasına neden olabilir.
Tek seferde en fazla 11 ses dosyasını birleştirebilirsiniz.
Parametreler
İşlem: audio/concat
Aşağıdaki tablolar parametreleri açıklamaktadır.
Birleştirme parametreleri
İstek dizesindeki pre ve sur parametrelerinin sırası, audio/concat için birleştirme düzenini belirler:
/pre: Başa eklenecek ses dosyası./sur: Sona eklenecek ses dosyası.
|
Parametre |
Tür |
Zorunlu |
Açıklama |
|
ss |
int |
Hayır |
Birleştirilecek ses klibinin başlangıç zamanı (milisaniye cinsinden). Geçerli değerler:
|
|
t |
int |
Hayır |
Başa veya sona eklenecek ses klibinin birleştirme süresi (milisaniye cinsinden). Geçerli değerler:
|
|
o |
string |
Evet |
Geçerli paketteki bir OSS nesnesi. Nesne adı URL güvenli Base64 kodlamasıyla kodlanmış olmalıdır. |
Kod dönüştürme parametreleri
|
Parametre |
Tür |
Zorunlu |
Açıklama |
|
ss |
int |
Hayır |
Ana ses dosyasının kod dönüştürme başlangıç zamanı (milisaniye cinsinden). Geçerli değerler:
|
|
t |
int |
Hayır |
Ana ses dosyasının kod dönüştürme süresi (milisaniye cinsinden). Geçerli değerler:
|
|
f |
string |
Evet |
Ses kapsayıcı biçimi:
|
|
ar |
int |
Hayır |
Ses örnekleme hızı. Varsayılan olarak, bu değer align ile belirtilen kaynak ses dosyasının hızıyla eşleşir. Geçerli değerler:
Not
Desteklenen örnekleme hızları biçime göre değişir. mp3 48 kHz ve altını; opus 8 kHz, 12 kHz, 16 kHz, 24 kHz ve 48 kHz'i; ac3 32 kHz, 44,1 kHz ve 48 kHz'i; amr ise yalnızca 8 kHz ve 16 kHz'i destekler. |
|
ac |
int |
Hayır |
Ses kanalı sayısı. Varsayılan olarak, bu değer align parametresiyle belirtilen kaynak ses dosyasının kanal sayısıyla eşleşir. Geçerli değerler: 1 ila 8. Not
Desteklenen kanal sayısı biçime göre değişir. mp3 mono ve stereo'yu; ac3 en fazla 6 kanalı (%5,1); amr ise yalnızca mono'yu destekler. |
|
aq |
int |
Hayır |
Ses sıkıştırma kalitesi. Geçerli değerler: 0 ila 100. Not
Bu parametre ab parametresiyle birlikte kullanılamaz. Hiçbiri ayarlanmazsa kodlayıcı varsayılan bit hızını kullanır. |
|
ab |
int |
Hayır |
Ses bit hızı (bit/s - bps cinsinden). Geçerli değerler: 1000 ila 10000000. |
|
abopt |
string |
Hayır |
Ses bit hızı seçeneği. Geçerli değerler:
Not
Bu parametre ab parametresiyle birlikte kullanılmalıdır. |
|
align |
int |
Hayır |
Birleştirme listesindeki ana ses dosyasının dizini. Varsayılan kod dönüştürme parametreleri bu dosyadan alınır. Varsayılan değer 0'dır ve bu, birleştirme listesindeki ilk ses dosyasını gösterir. |
|
adepth |
int |
Hayır |
Ses örnekleme bit derinliği. Geçerli değerler: 16 ve 24. Not
Bu parametre yalnızca f flac olarak ayarlandığında etkili olur. |
Ses birleştirme işlemi ayrıca sys/saveas ve notify parametrelerini de kullanır. Daha fazla bilgi için bkz. farklı kaydet ve Mesaj bildirimi.
REST API
Sesi AAC biçimine birleştirme
Ses dosyaları: pre1.mp3, pre2.wav, example.oga, sur1.aac, sur2.wma
-
Birleştirme süresi ve sırası:
Ses adı
Sıra
Süre
pre1.mp3
1
Sesin tamamı
pre2.wav
2
İlk 2 saniye
example.oga
3
Sesin tamamı
sur1.aac
4
4. sn - 10. sn
sur2.wma
5
10. sn - son Kod dönüştürme tamamlama bildirimi: Message Service (MNS) mesajı gönderilir.
-
Çıktı ses teknik özellikleri
Ses biçimi: aac
Ses profili: 44,1 kHz örnekleme hızı, mono
Ses bit hızı: 96 kbps
-
Nesne depolama yolu
AAC dosyası: oss://outbucket/outobj.aac
Örnek istek
// Perform audio merging on the example.oga object.
POST /example.oga?x-oss-async-process HTTP/1.1
Host: video-demo.oss-cn-hangzhou.aliyuncs.com
Date: Fri, 28 Oct 2022 06:40:10 GMT
Authorization: OSS4-HMAC-SHA256 Credential=LTAI********************/20250417/cn-hangzhou/oss/aliyun_v4_request,Signature=a7c3554c729d71929e0b84489addee6b2e8d5cb48595adfc51868c299c0c218e
x-oss-async-process=audio/concat,f_aac,ac_1,ar_44100,ab_96000,align_2/pre,o_cHJlMS5tcDMK/pre,o_cHJlMi53YXYK,t_2000/sur,o_c3VyMS5hYWMK,ss_4000,t_10000/sur,o_c3VyMi53bWEK,ss_10000|sys/saveas,b_b3V0YnVja2V0,o_b3V0b2JqLnthdXRvZXh0fQo/notify,topic_QXVkaW9Db252ZXJ0
OSS SDK'ları
Java, Python veya Go için OSS SDK'yı kullanarak eşzamansız işleme ile ses birleştirme işlemini gerçekleştirebilirsiniz.
Ön koşullar
OSS_ACCESS_KEY_IDveOSS_ACCESS_KEY_SECRETortam değişkenlerinin ayarlandığından emin olun.Paket adını belirtin, örneğin
examplebucket.Çıktı ses dosyasının adını belirtin, örneğin
dest.aac.Birleştirilecek kaynak ses dosyalarının adlarını belirtin, örneğin
src1.mp3vesrc2.mp3.
Java
Java için OSS SDK 3.17.4 veya sonraki bir sürüm gereklidir.
import com.aliyun.oss.ClientBuilderConfiguration;
import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import com.aliyun.oss.common.auth.CredentialsProviderFactory;
import com.aliyun.oss.common.auth.EnvironmentVariableCredentialsProvider;
import com.aliyun.oss.common.comm.SignVersion;
import com.aliyun.oss.model.AsyncProcessObjectRequest;
import com.aliyun.oss.model.AsyncProcessObjectResult;
import com.aliyuncs.exceptions.ClientException;
import java.nio.charset.StandardCharsets;
import java.util.Base64;
public class Demo {
public static void main(String[] args) throws ClientException {
// Set endpoint to the endpoint of the region where the bucket is located.
String endpoint = "https://oss-cn-hangzhou.aliyuncs.com";
// Specify the Alibaba Cloud region ID, for example, cn-hangzhou.
String region = "cn-hangzhou";
// Obtain access credentials from environment variables. Before running this sample code, make sure the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
EnvironmentVariableCredentialsProvider credentialsProvider = CredentialsProviderFactory.newEnvironmentVariableCredentialsProvider();
// Specify the bucket name.
String bucketName = "examplebucket";
// Specify the name of the output audio file.
String targetAudio = "dest.aac";
// Specify the names of the audio files to be merged.
String audio1 = "src1.mp3";
String audio2 = "src2.mp3";
// Create an OSSClient instance.
// When you are finished, shut down the OSSClient to release resources.
ClientBuilderConfiguration clientBuilderConfiguration = new ClientBuilderConfiguration();
clientBuilderConfiguration.setSignatureVersion(SignVersion.V4);
OSS ossClient = OSSClientBuilder.create()
.endpoint(endpoint)
.credentialsProvider(credentialsProvider)
.clientConfiguration(clientBuilderConfiguration)
.region(region)
.build();
try {
// Build the style string for audio processing and the audio merging parameters.
String audio1Encoded = Base64.getUrlEncoder().encodeToString(audio1.getBytes(StandardCharsets.UTF_8)).replace("=", "");
String audio2Encoded = Base64.getUrlEncoder().encodeToString(audio2.getBytes(StandardCharsets.UTF_8)).replace("=", "");
String style = String.format("audio/concat,f_aac,ac_1,ar_44100,ab_96000,align_2/pre,o_%s/pre,o_%s,t_0", audio1Encoded, audio2Encoded);
// Build the asynchronous processing instruction.
String bucketEncoded = Base64.getUrlEncoder().encodeToString(bucketName.getBytes(StandardCharsets.UTF_8)).replace("=", "");
String targetEncoded = Base64.getUrlEncoder().encodeToString(targetAudio.getBytes(StandardCharsets.UTF_8)).replace("=", "");
String process = String.format("%s|sys/saveas,b_%s,o_%s/notify,topic_QXVkaW9Db252ZXJ0", style, bucketEncoded, targetEncoded);
// Create an AsyncProcessObjectRequest object.
AsyncProcessObjectRequest request = new AsyncProcessObjectRequest(bucketName, audio1, process);
// Execute the asynchronous processing task.
AsyncProcessObjectResult response = ossClient.asyncProcessObject(request);
System.out.println("EventId: " + response.getEventId());
System.out.println("RequestId: " + response.getRequestId());
System.out.println("TaskId: " + response.getTaskId());
} finally {
// Shut down the OSSClient.
ossClient.shutdown();
}
}
}
Python
Python için OSS SDK 2.18.4 veya sonraki bir sürüm gereklidir.
# -*- coding: utf-8 -*-
import base64
import oss2
from oss2.credentials import EnvironmentVariableCredentialsProvider
def main():
# Obtain access credentials from environment variables. Before running this sample code, make sure the OSS_ACCESS_KEY_ID and OSS_ACCESS_KEY_SECRET environment variables are set.
auth = oss2.ProviderAuthV4(EnvironmentVariableCredentialsProvider())
# Set endpoint to the endpoint of the region where the bucket is located. For example, for China (Hangzhou), set the endpoint to https://oss-cn-hangzhou.aliyuncs.com.
endpoint = 'https://oss-cn-hangzhou.aliyuncs.com'
# Specify the Alibaba Cloud region ID, for example, cn-hangzhou.
region = 'cn-hangzhou'
# Specify the bucket name, for example, examplebucket.
bucket = oss2.Bucket(auth, endpoint, 'examplebucket', region=region)
# Specify the name of the output audio file.
target_audio = 'dest.aac'
# Specify the names of the audio files to merge.
audio1 = 'src1.mp3'
audio2 = 'src2.mp3'
# Build the style string for audio processing and the audio merging parameters.
audio1_encoded = base64.urlsafe_b64encode(audio1.encode()).decode().rstrip('=')
audio2_encoded = base64.urlsafe_b64encode(audio2.encode()).decode().rstrip('=')
style = f"audio/concat,f_aac,ac_1,ar_44100,ab_96000,align_2/pre,o_{audio1_encoded}/pre,o_{audio2_encoded},t_0"
# Build the asynchronous processing instruction.
bucket_encoded = base64.urlsafe_b64encode(bucket.bucket_name.encode()).decode().rstrip('=')
target_encoded = base64.urlsafe_b64encode(target_audio.encode()).decode().rstrip('=')
process = f"{style}|sys/saveas,b_{bucket_encoded},o_{target_encoded}/notify,topic_QXVkaW9Db252ZXJ0"
print(process)
# Execute the asynchronous processing task.
try:
result = bucket.async_process_object(audio1, process)
print(f"EventId: {result.event_id}")
print(f"RequestId: {result.request_id}")
print(f"TaskId: {result.task_id}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()
Go
Go için OSS SDK 3.0.2 veya sonraki bir sürüm gereklidir.
package main
import (
"encoding/base64"
"fmt"
"log"
"os"
"github.com/aliyun/aliyun-oss-go-sdk/oss"
)
func main() {
// Obtain access credentials from environment variables. Before running this sample code, make sure the OSS_ACCESS_KEY_ID, OSS_ACCESS_KEY_SECRET, and OSS_SESSION_TOKEN environment variables are set.
provider, err := oss.NewEnvironmentVariableCredentialsProvider()
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Create an OSSClient instance.
// Set endpoint to the endpoint of the region where your bucket is located. For example, for China (Hangzhou), set it to https://oss-cn-hangzhou.aliyuncs.com.
// Set region to the Alibaba Cloud region ID, for example, cn-hangzhou.
client, err := oss.New("https://oss-cn-hangzhou.aliyuncs.com", "", "", oss.SetCredentialsProvider(&provider), oss.AuthVersion(oss.AuthV4), oss.Region("cn-hangzhou"))
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the bucket name, for example, examplebucket.
bucketName := "examplebucket"
bucket, err := client.Bucket(bucketName)
if err != nil {
fmt.Println("Error:", err)
os.Exit(-1)
}
// Specify the names of the audio files to be merged.
audio1 := "src1.mp3"
audio2 := "src2.mp3"
// Specify the name of the output audio file.
targetAudio := "dest.aac"
// Build the style string for audio processing and the audio merging parameters.
audio1Encoded := base64.URLEncoding.EncodeToString([]byte(audio1))
audio2Encoded := base64.URLEncoding.EncodeToString([]byte(audio2))
style := fmt.Sprintf("audio/concat,f_aac,ac_1,ar_44100,ab_96000,align_2/pre,o_%s/pre,o_%s,t_0", audio1Encoded, audio2Encoded)
// Build the asynchronous processing instruction.
bucketEncoded := base64.URLEncoding.EncodeToString([]byte(bucketName))
targetEncoded := base64.URLEncoding.EncodeToString([]byte(targetAudio))
process := fmt.Sprintf("%s|sys/saveas,b_%s,o_%s/notify,topic_QXVkaW9Db252ZXJ0", style, bucketEncoded, targetEncoded)
// Execute the asynchronous processing task.
result, err := bucket.AsyncProcessObject(audio1, process)
if err != nil {
log.Fatalf("Failed to async process object: %s", err)
}
fmt.Printf("EventId: %s\n", result.EventId)
fmt.Printf("RequestId: %s\n", result.RequestId)
fmt.Printf("TaskId: %s\n", result.TaskId)
}